class MaxMind::GeoIP2::Model::City
Model
class for the data returned by the GeoIP2
City
web service and database. It is also used for GeoLite2 City
lookups.
The only difference between the City
and Insights
model classes is which fields in each record may be populated. See dev.maxmind.com/geoip/geoip2/web-services for more details.
See {MaxMind::GeoIP2::Model::Country} for inherited methods.
Attributes
City
data for the IP address.
@return [MaxMind::GeoIP2::Record::City]
Location data for the IP address.
@return [MaxMind::GeoIP2::Record::Location]
Postal data for the IP address.
@return [MaxMind::GeoIP2::Record::Postal]
The country subdivisions for the IP address.
The number and type of subdivisions varies by country, but a subdivision is typically a state, province, country, etc. Subdivisions are ordered from most general (largest) to most specific (smallest).
If the response did not contain any subdivisions, this attribute will be an empty array.
@return [Array<MaxMind::GeoIP2::Record::Subdivision>]
Public Class Methods
@!visibility private
# File lib/maxmind/geoip2/model/city.rb, line 69 def initialize(record, locales) super(record, locales) @city = MaxMind::GeoIP2::Record::City.new(record['city'], locales) @location = MaxMind::GeoIP2::Record::Location.new(record['location']) @postal = MaxMind::GeoIP2::Record::Postal.new(record['postal']) @subdivisions = create_subdivisions(record['subdivisions'], locales) end
Public Instance Methods
The most specific subdivision returned.
If the response did not contain any subdivisions, this method returns nil.
@return [MaxMind::GeoIP2::Record::Subdivision, nil]
# File lib/maxmind/geoip2/model/city.rb, line 83 def most_specific_subdivision @subdivisions.last end
Private Instance Methods
# File lib/maxmind/geoip2/model/city.rb, line 89 def create_subdivisions(subdivisions, locales) return [] if subdivisions.nil? subdivisions.map do |s| MaxMind::GeoIP2::Record::Subdivision.new(s, locales) end end