class Terragona::GeoNames::Base
Public Class Methods
new(args = {})
click to toggle source
# File lib/terragona/geonames.rb, line 10 def initialize(args = {}) @default_country = args[:default_country] end
Public Instance Methods
search(options)
click to toggle source
# File lib/terragona/geonames.rb, line 14 def search(options) country = options[:country] || @default_country id = options[:id] name = options[:name] fcode = options[:fcode] children_fcode = options[:children_fcode] || case fcode when 'PCLI' then 'ADM1' when 'ADM1' then 'ADM2' when 'ADM2' then 'ADM3' when 'ADM3' then 'ADM4' when 'ADM4' then 'ADM5' when 'PPLC' then 'PPLX' end field_to_compare = options[:field_to_compare] || calculate_field_to_compare(fcode) children_field_to_compare = calculate_field_to_compare(children_fcode) field_to_compare_value = options[:field_to_compare_value] if field_to_compare_value.nil? fetch_geonames(name,country,nil,nil).each{|g| if g[:fcode] == fcode name = g[:name] id = g[:geonameId] field_to_compare_value = g[field_to_compare] break end } end points = [] children_places = [] fetch_geonames(nil,country,field_to_compare,field_to_compare_value).each{|g| points.push({:x=>g[:lng],:y=>g[:lat]}) if g[:fcode] == children_fcode and children_field_to_compare child={:name=>g[:name], :id=>g[:geonameId], :fcode=>g[:fcode], :country=>g[:countryCode], :field_to_compare_value=>g[children_field_to_compare]} children_places.push(child) end } {:children_places=>children_places,:points=>points,:place_name=>name,:place_id=>id} end
Private Instance Methods
calculate_field_to_compare(fcode)
click to toggle source
# File lib/terragona/geonames.rb, line 64 def calculate_field_to_compare(fcode) case fcode when 'PCLI' then :countryCode when 'ADM1' then :adminCode1 when 'ADM2' then :adminCode2 when 'ADM3' then :adminCode3 else nil end end