module Reality::Dictionaries
Constants
- CITIES_PAGE_BY_COUNTRY
- CITY_SYNONYMS
Public Instance Methods
cities_by_country(name)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/reality/definitions/dictionaries.rb, line 7 def countries List.new(*countries_by_continents_cache.keys) end
countries_by_continent(name)
click to toggle source
# 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()
click to toggle source
# 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