Module: WineDb::Matcher
- Included in:
- Reader
- Defined in:
- lib/winedb/reader.rb
Instance Method Summary collapse
-
#fix_match_xxx_for_country_n_region(name, xxx) ⇒ Object
xxx e.g.
- #match_shops_for_country_n_region(name, &blk) ⇒ Object
- #match_taverns_for_country_n_region(name, &blk) ⇒ Object
-
#match_vineyards_for_country_n_region(name, &blk) ⇒ Object
for now vineyards, shops, taverns require country n region.
- #match_wineries_for_country(name, &blk) ⇒ Object
- #match_wineries_for_country_n_region(name, &blk) ⇒ Object
- #match_wines_for_country(name, &blk) ⇒ Object
- #match_wines_for_country_n_region(name, &blk) ⇒ Object
Instance Method Details
#fix_match_xxx_for_country_n_region(name, xxx) ⇒ Object
xxx e.g. wine|wineries
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/winedb/reader.rb', line 8 def fix_match_xxx_for_country_n_region( name, xxx ) # xxx e.g. wine|wineries ## todo/fix: move code into worlddb matcher!!!! ## -- allow opt_folders after long regions ## -- allow anything before -- for xxx ### fix allow prefixes for wines (move into core!!!) e.g. ## # at-austria!/1--n-niederoesterreich--eastern/wagram--wines # at-austria!/1--n-niederoesterreich--eastern/wagram--wagram--wines ### strip subregion if present e.g. # /wagram--wines becomes /wines n # /wagram--wagram--wines becomes / wines etc. # auto-add required country n region code (from folder structure) # note: allow /cities and /1--hokkaido--cities and /hokkaido--cities too xxx_pattern = "(?:#{xxx}|[^\\/]+--#{xxx})" # note: double escape \\ required for backslash ## allow optional folders -- TODO: add restriction ?? e.g. must be 4+ alphas ??? opt_folders_pattern = "(?:\/[^\/]+)*" ## note: for now only (2) n (3) that is long region allow opt folders if name =~ /(?:^|\/)([a-z]{2,3})-[^\/]+\/([a-z]{1,3})-[^\/]+\/#{xxx_pattern}/ || # (1) name =~ /(?:^|\/)[0-9]+--([a-z]{2,3})-[^\/]+\/[0-9]+--([a-z]{1,3})-[^\/]+#{opt_folders_pattern}\/#{xxx_pattern}/ || # (2) name =~ /(?:^|\/)([a-z]{2,3})-[^\/]+\/[0-9]+--([a-z]{1,3})-[^\/]+#{opt_folders_pattern}\/#{xxx_pattern}/ || # (3) name =~ /(?:^|\/)[0-9]+--([a-z]{2,3})-[^\/]+\/([a-z]{1,3})-[^\/]+\/#{xxx_pattern}/ # (4) ####### # nb: country must start name (^) or coming after / e.g. europe/at-austria/... # (1) # new style: e.g. /at-austria/w-wien/cities or # ^at-austria!/w-wien/cities # (2) # new new style e.g. /1--at-austria--central/1--w-wien--eastern/cities # # (3) # new new mixed style e.g. /at-austria/1--w-wien--eastern/cities # "classic" country plus new new region # # (4) # new new mixed style e.g. /1--at-austria--central/w-wien/cities # new new country plus "classic" region country_key = $1.dup region_key = $2.dup yield( country_key, region_key ) true # bingo - match found else false # no match found end end |
#match_shops_for_country_n_region(name, &blk) ⇒ Object
86 87 88 89 |
# File 'lib/winedb/reader.rb', line 86 def match_shops_for_country_n_region( name, &blk ) ## check: allow/add synonyms e.g. vinotheken, enotecas fix_match_xxx_for_country_n_region( name, 'shops', &blk ) end |
#match_taverns_for_country_n_region(name, &blk) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/winedb/reader.rb', line 91 def match_taverns_for_country_n_region( name, &blk ) ## also try synonyms e.g. heurige (if not match for taverns) found = fix_match_xxx_for_country_n_region( name, 'taverns', &blk ) found = fix_match_xxx_for_country_n_region( name, 'heurige', &blk ) unless found found end |
#match_vineyards_for_country_n_region(name, &blk) ⇒ Object
for now vineyards, shops, taverns require country n region
82 83 84 |
# File 'lib/winedb/reader.rb', line 82 def match_vineyards_for_country_n_region( name, &blk ) fix_match_xxx_for_country_n_region( name, 'vineyards', &blk ) end |
#match_wineries_for_country(name, &blk) ⇒ Object
72 73 74 |
# File 'lib/winedb/reader.rb', line 72 def match_wineries_for_country( name, &blk ) match_xxx_for_country( name, 'wineries', &blk ) end |
#match_wineries_for_country_n_region(name, &blk) ⇒ Object
76 77 78 79 |
# File 'lib/winedb/reader.rb', line 76 def match_wineries_for_country_n_region( name, &blk ) ## check: allow/add synonyms e.g. producers ? weingueter ?? fix_match_xxx_for_country_n_region( name, 'wineries', &blk ) end |
#match_wines_for_country(name, &blk) ⇒ Object
63 64 65 66 |
# File 'lib/winedb/reader.rb', line 63 def match_wines_for_country( name, &blk ) ## check: allow/add synonyms e.g. weine, vinos etc. ??? match_xxx_for_country( name, 'wines', &blk ) end |
#match_wines_for_country_n_region(name, &blk) ⇒ Object
68 69 70 |
# File 'lib/winedb/reader.rb', line 68 def match_wines_for_country_n_region( name, &blk ) fix_match_xxx_for_country_n_region( name, 'wines', &blk ) end |