Class: IParty::MaxMind::Result::NamedLocation

Inherits:
IParty::MaxMind::Result show all
Defined in:
lib/iparty/max_mind/result.rb

Direct Known Subclasses

City, Continent, Country, Subdivision

Instance Method Summary collapse

Methods inherited from IParty::MaxMind::Result

define_attr, export_attr, #initialize, #inspect, #presence, #present?

Constructor Details

This class inherits a constructor from IParty::MaxMind::Result

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/iparty/max_mind/result.rb', line 84

def method_missing method_name, *arguments
  if method_name.end_with?("?")
    method_name[0..-2] == (method_name.length == 3 ? inquire_on_code : inquire_on_name)
  else
    super
  end
end

Instance Method Details

#==(other) ⇒ Object

dynamic comparison



65
66
67
68
69
70
71
72
73
74
# File 'lib/iparty/max_mind/result.rb', line 65

def == other
  case other
  when String
    name && other == name
  when Numeric
    geoname_id && other == geoname_id
  else
    super
  end
end

#name(locale = :en, fallback_locale: :en) ⇒ Object Also known as: to_s



54
55
56
57
58
# File 'lib/iparty/max_mind/result.rb', line 54

def name(locale = :en, fallback_locale: :en)
  return unless all = dig(:names)

  all[locale] || (all[fallback_locale] if fallback_locale)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/iparty/max_mind/result.rb', line 80

def respond_to_missing? method_name, include_private = false
  method_name.end_with?("?") || super
end