class CitySearch
Public Instance Methods
db()
click to toggle source
# File lib/city_search.rb, line 21 def db @all ||= Dawg.load(File.join(data_path, 'russia.bin')) end
search(q)
click to toggle source
# File lib/city_search.rb, line 4 def search(q) results = db.query(q.downcase).reject {|r| r.empty? } results.map do |r| result = r.split(' ') code = result.last result.pop city_name = result.join(' ') .split .map(&:capitalize) .join(' ') state = states[code.to_i] [city_name, state] end end
states()
click to toggle source
# File lib/city_search.rb, line 25 def states @states ||= Marshal.load( File.read(File.join(data_path, 'subdivisions.bin')) ) end
Private Instance Methods
data_path()
click to toggle source
# File lib/city_search.rb, line 33 def data_path @data_path ||= File.join(File.dirname(__FILE__), '/../data') end