1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
require 'geocoder/results/base'
module Geocoder::Result
class IpinfoIo < Base
def address(format = :full)
"#{city} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
end
def coordinates
@data['loc'].to_s.split(",").map(&:to_f)
end
def city
@data['city']
end
def state
@data['region']
end
def country
@data['country']
end
def postal_code
@data['postal']
end
def country_code
@data.fetch('country', '')
end
def state_code
@data.fetch('region_code', '')
end
def self.response_attributes
%w(ip region postal)
end
response_attributes.each do |a|
define_method a do
@data[a]
end
end
end
end
|