diff options
Diffstat (limited to 'pkg/adapters/xlsx/model.go')
| -rw-r--r-- | pkg/adapters/xlsx/model.go | 60 |
1 files changed, 8 insertions, 52 deletions
diff --git a/pkg/adapters/xlsx/model.go b/pkg/adapters/xlsx/model.go index d8c5194..79434f0 100644 --- a/pkg/adapters/xlsx/model.go +++ b/pkg/adapters/xlsx/model.go @@ -1,13 +1,13 @@ package xlsx import ( + "airlines/pkg/model" "errors" - "regexp" "strconv" "strings" "time" - "github.com/leonm1/airports-go" + "airlines/pkg/airports" ) type Ticket struct { @@ -16,9 +16,13 @@ type Ticket struct { Title string FlightNumber string FromCity string - ToCity string + FromCountry string FromAirport string + FromCoords model.LatLong + ToCity string + ToCountry string ToAirport string + ToCoords model.LatLong FlightDate string // (raw, expected YYYY-MM-DD; Excel text may start with ') FlightTime string // (raw, expected HH-MM or HH:MM; Excel text may start with ') PNR string @@ -87,52 +91,4 @@ func two(x int) string { return "0" + strconv.Itoa(x) } return strconv.Itoa(x) -} - -func parseCardLine(s string) (prefix string, number uint64, bonus string) { - raw := strings.TrimSpace(s) - if raw == "" { - return "", 0, "" - } - // number = last run of digits - if m := regexp.MustCompile(`(\d{3,})\D*$`).FindStringSubmatch(raw); len(m) == 2 { - if n, err := strconv.ParseUint(m[1], 10, 64); err == nil { - number = n - } - } - - // tokens (letters with '-', '/', apostrophes) - tokRe := regexp.MustCompile(`[A-Za-z][A-Za-z'/-]*`) - toks := tokRe.FindAllString(s, -1) - - // prefix = first 2–3 letter all-caps-ish token - for _, t := range toks { - u := strings.ToUpper(t) - if len(u) >= 2 && len(u) <= 3 && regexp.MustCompile(`^[A-Z]{2,3}$`).MatchString(u) { - prefix = u - break - } - } - // bonus = all tokens except prefix - words := []string{} - for _, t := range toks { - if strings.ToUpper(t) == prefix { - continue - } - words = append(words, t) - } - if len(words) > 0 { - bonus = strings.Join(words, " ") - } - if bonus == "" && prefix != "" { - bonus = prefix - } - return -} - -func firstNonEmpty(a, b string) string { - if strings.TrimSpace(a) != "" { - return a - } - return b -} +}
\ No newline at end of file |
