Class: Ipregistry::Models::Base
- Inherits:
-
Object
- Object
- Ipregistry::Models::Base
- Defined in:
- lib/ipregistry/models/base.rb
Overview
Base class for all response models. Wraps the decoded JSON hash and exposes convenient readers declared with a small class-level DSL.
Direct Known Subclasses
Carrier, Company, Connection, Continent, Country, Currency, CurrencyFormat, CurrencyFormatAffix, Flag, IpInfo, Language, Location, Region, Security, TimeZone, UserAgent, UserAgentDevice, UserAgentEngine, UserAgentOperatingSystem
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#[](key) ⇒ Object
Raw access to any field of the payload, including ones without a dedicated reader.
- #hash ⇒ Object
-
#initialize(data = {}) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
-
#to_h ⇒ Hash
The raw decoded payload backing this model.
Constructor Details
#initialize(data = {}) ⇒ Base
Returns a new instance of Base.
14 15 16 |
# File 'lib/ipregistry/models/base.rb', line 14 def initialize(data = {}) @data = data.is_a?(Hash) ? data : {} end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
30 31 32 |
# File 'lib/ipregistry/models/base.rb', line 30 def ==(other) other.instance_of?(self.class) && other.to_h == @data end |
#[](key) ⇒ Object
Raw access to any field of the payload, including ones without a dedicated reader.
26 27 28 |
# File 'lib/ipregistry/models/base.rb', line 26 def [](key) @data[key.to_s] end |
#hash ⇒ Object
35 36 37 |
# File 'lib/ipregistry/models/base.rb', line 35 def hash [self.class, @data].hash end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/ipregistry/models/base.rb', line 39 def inspect "#<#{self.class.name} #{@data.inspect}>" end |
#to_h ⇒ Hash
The raw decoded payload backing this model.
20 21 22 |
# File 'lib/ipregistry/models/base.rb', line 20 def to_h @data end |