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[R]

City data for the IP address.

@return [MaxMind::GeoIP2::Record::City]

location[R]

Location data for the IP address.

@return [MaxMind::GeoIP2::Record::Location]

postal[R]

Postal data for the IP address.

@return [MaxMind::GeoIP2::Record::Postal]

subdivisions[R]

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

new(record, locales) click to toggle source

@!visibility private

Calls superclass method
# File lib/maxmind/geoip2/model/city.rb, line 49
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

most_specific_subdivision() click to toggle source

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 63
def most_specific_subdivision
  @subdivisions.last
end

Private Instance Methods

create_subdivisions(subdivisions, locales) click to toggle source
# File lib/maxmind/geoip2/model/city.rb, line 69
def create_subdivisions(subdivisions, locales)
  return [] if subdivisions.nil?

  subdivisions.map do |s|
    MaxMind::GeoIP2::Record::Subdivision.new(s, locales)
  end
end