Module: WorldDb::Matcher
- Included in:
- ReaderBase
- Defined in:
- lib/worlddb/matcher.rb,
lib/worlddb/matcher_adm.rb
Instance Method Summary collapse
- #match_adm2_counties_for_country(name, &blk) ⇒ Object
- #match_adm2_parts_for_country(name, &blk) ⇒ Object
- #match_adm3_counties_for_country(name, &blk) ⇒ Object
- #match_cities_for_country(name, &blk) ⇒ Object
- #match_countries_for_continent(name) ⇒ Object
-
#match_states_abbr_for_country(name, &blk) ⇒ Object
NB: .
- #match_states_for_country(name, &blk) ⇒ Object
-
#match_states_iso_for_country(name, &blk) ⇒ Object
NB: .
-
#match_states_nuts_for_country(name, &blk) ⇒ Object
NB: .
-
#match_tree_for_country(name, &blk) ⇒ Object
rename to state_tree ?? why? why not??.
Instance Method Details
#match_adm2_counties_for_country(name, &blk) ⇒ Object
16 17 18 19 |
# File 'lib/worlddb/matcher_adm.rb', line 16 def match_adm2_counties_for_country( name, &blk ) ## note: counties might also be an adm3 match match_xxx_for_country_n_adm1( name, 'counties', &blk ) end |
#match_adm2_parts_for_country(name, &blk) ⇒ Object
12 13 14 |
# File 'lib/worlddb/matcher_adm.rb', line 12 def match_adm2_parts_for_country( name, &blk ) match_xxx_for_country_n_adm1( name, 'parts', &blk ) end |
#match_adm3_counties_for_country(name, &blk) ⇒ Object
21 22 23 |
# File 'lib/worlddb/matcher_adm.rb', line 21 def match_adm3_counties_for_country( name, &blk ) match_xxx_for_country_n_adm1_n_adm2( name, 'counties', &blk ) end |
#match_cities_for_country(name, &blk) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/worlddb/matcher.rb', line 15 def match_cities_for_country( name, &blk ) ## todo: check if there's a better (more ruby way) to pass along code block ?? ## e.g. try ## match_xxx_for_country( name, 'cities') { |country_key| yield(country_key) } match_xxx_for_country( name, 'cities', &blk ) end |
#match_countries_for_continent(name) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/worlddb/matcher.rb', line 55 def match_countries_for_continent( name ) if name =~ /^([a-z][a-z\-_]+[a-z])\/countries/ # e.g. africa/countries or america/countries ### NB: continent changed to regions (e.g. middle-east, caribbean, north-america, etc.) ## auto-add continent (from folder structure) as tag ## fix: allow dash/hyphen/minus in tag continent = $1.dup yield( continent ) true else false # no match found end end |
#match_states_abbr_for_country(name, &blk) ⇒ Object
NB: . gets escaped for regex, that is, .
33 34 35 36 37 38 |
# File 'lib/worlddb/matcher.rb', line 33 def match_states_abbr_for_country( name, &blk ) # NB: . gets escaped for regex, that is, \. ## also try synonyms e.g. old regions (if not match for states) found = match_xxx_for_country( name, 'states\.abbr', &blk ) found = match_xxx_for_country( name, 'regions\.abbr', &blk ) unless found found end |
#match_states_for_country(name, &blk) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/worlddb/matcher.rb', line 25 def match_states_for_country( name, &blk ) ## todo/fix: remove regions (obsolete) - no longer supported ## also try synonyms e.g. old regions (if not match for states) found = match_xxx_for_country( name, 'states', &blk ) found = match_xxx_for_country( name, 'regions', &blk ) unless found found end |
#match_states_iso_for_country(name, &blk) ⇒ Object
NB: . gets escaped for regex, that is, .
40 41 42 43 44 45 |
# File 'lib/worlddb/matcher.rb', line 40 def match_states_iso_for_country( name, &blk ) # NB: . gets escaped for regex, that is, \. ## also try synonyms e.g. old regions (if not match for states) found = match_xxx_for_country( name, 'states\.iso', &blk ) found = match_xxx_for_country( name, 'regions\.iso', &blk ) unless found found end |
#match_states_nuts_for_country(name, &blk) ⇒ Object
NB: . gets escaped for regex, that is, .
47 48 49 50 51 52 |
# File 'lib/worlddb/matcher.rb', line 47 def match_states_nuts_for_country( name, &blk ) # NB: . gets escaped for regex, that is, \. ## also try synonyms e.g. old regions (if not match for states) found = match_xxx_for_country( name, 'states\.nuts', &blk ) found = match_xxx_for_country( name, 'regions\.nuts', &blk ) unless found found end |
#match_tree_for_country(name, &blk) ⇒ Object
rename to state_tree ?? why? why not??
7 8 9 10 11 12 |
# File 'lib/worlddb/matcher.rb', line 7 def match_tree_for_country( name, &blk ) ## rename to state_tree ?? why? why not?? ## match state_tree (for now use orte.txt for austria, deutschland etc.) ## todo/fix: add more "generic" names simple_match_xxx_for_country( name, 'orte', &blk ) ## note: uses special **simple**_match_xxx_... end |