Module: Reality::Dictionaries
- Defined in:
- lib/reality/definitions/dictionaries.rb
Constant Summary collapse
- CITY_SYNONYMS =
[ 'City', 'Municipality', 'Commune', # France 'GCCSA/SUA' # Australia ]
- CITIES_PAGE_BY_COUNTRY =
Hash.new{|_, name| 'List of cities in %s' % name}. merge( 'United States' => 'List of United States cities by population', 'Australia' => 'List of cities in Australia by population' )
Class Method Summary collapse
- .cities_by_country(name) ⇒ Object
- .continents ⇒ Object
- .countries ⇒ Object
- .countries_by_continent(name) ⇒ Object
- .countries_by_continents_cache ⇒ Object
Class Method Details
.cities_by_country(name) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/reality/definitions/dictionaries.rb', line 33 def cities_by_country(name) page = Infoboxer.wp.get(CITIES_PAGE_BY_COUNTRY[name]) or return Entity::List.new() page.tables.map{|t| t.heading_row or next [] idx = t.heading_row.children. index{|c| c.text =~ /\bname\b/i || CITY_SYNONYMS.any?{|s| c.text.strip.start_with?(s)}} or next [] t.lookup(:TableCell, index: idx).lookup(:Wikilink) }.flatten. derp{|links| Entity::Coercion.coerce(links, [:entity])} end |
.continents ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/reality/definitions/dictionaries.rb', line 11 def continents @continents ||= Infoboxer.wp.get('Continent'). sections('Area and population').tables.first. lookup(:TableHeading, index: 0).lookup(:Wikilink). derp{|links| Entity::Coercion.coerce(links, [:entity])} end |
.countries ⇒ Object
7 8 9 |
# File 'lib/reality/definitions/dictionaries.rb', line 7 def countries List.new(*countries_by_continents_cache.keys) end |
.countries_by_continent(name) ⇒ Object
48 49 50 51 |
# File 'lib/reality/definitions/dictionaries.rb', line 48 def countries_by_continent(name) countries_by_continents_cache.select{|k, v| v == name}.map(&:first). derp{|names| List.new(*names)} end |
.countries_by_continents_cache ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/reality/definitions/dictionaries.rb', line 53 def countries_by_continents_cache @by_continents ||= Infoboxer.wp. get('List of countries by continent'). sections.first. sections.map{|s| continent = s.heading.text_ s.tables.first. lookup(:Wikilink, :bold?).map(&:link). map{|country| [country, continent]} }.flatten(1). reject{|country, continent| country == 'Holy See'}. # it has [Vatican City]/[Holy See] to_h end |