Class: Terragona::GeoNames::Dump

Inherits:
Base
  • Object
show all
Defined in:
lib/terragona/geonames.rb

Constant Summary collapse

HEADERS =
[:geonameId, 
:name, 
:asciiname, 
:alternatenames, 
:lat,
:lng,
:fclass,
:fcode,
:countryCode,
:cc2,
:adminCode1,
:adminCode2,
:adminCode3,
:adminCode4,
:population,
:elevation,
:dem,
:timezone,
:modificaion_date]

Instance Method Summary collapse

Methods inherited from Base

#search

Constructor Details

#initialize(args = {}) ⇒ Dump

Returns a new instance of Dump.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/terragona/geonames.rb', line 127

def initialize(args = {})
  super
  
  if not args[:dump]
    puts 'No dump file provided'
    return
  end
  @file = File.open(args[:dump])
  @admin_codes_cache = {:adminCode1=>{},
                        :adminCode2=>{},
                        :adminCode3=>{},
                        :adminCode4=>{}}
                        
  @max_points = args[:max_points]                    
end

Instance Method Details

#fetch_geonames(name, country, admin_code_type, admin_code) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/terragona/geonames.rb', line 143

def fetch_geonames(name, country, admin_code_type, admin_code)
  if admin_code_type and 
     @admin_codes_cache[admin_code_type] and 
     @admin_codes_cache[admin_code_type][admin_code]
  
    @admin_codes_cache[admin_code_type][admin_code]
     
  else
    dump_parser(name, country, admin_code_type, admin_code)
  end
end