Class: Focus
- Inherits:
-
Object
- Object
- Focus
- Includes:
- HTTParty
- Defined in:
- lib/focus.rb,
lib/focus/data.rb,
lib/focus/country.rb,
lib/focus/location.rb
Defined Under Namespace
Classes: Country, Data, Location
Instance Attribute Summary collapse
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
Class Method Summary collapse
-
.key(ip_address, prefix = "focus") ⇒ Object
generate a key from the ip_address.
Instance Method Summary collapse
- #country ⇒ Object
-
#initialize(ip_address) ⇒ Focus
constructor
A new instance of Focus.
- #location ⇒ Object
Constructor Details
#initialize(ip_address) ⇒ Focus
Returns a new instance of Focus.
15 16 17 18 19 20 |
# File 'lib/focus.rb', line 15 def initialize(ip_address) raise unless Focus.valid?(ip_address) @ip = ip_address self.locate self end |
Instance Attribute Details
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
13 14 15 |
# File 'lib/focus.rb', line 13 def ip @ip end |
Class Method Details
.key(ip_address, prefix = "focus") ⇒ Object
generate a key from the ip_address
23 24 25 26 27 28 29 30 |
# File 'lib/focus.rb', line 23 def self.key(ip_address, prefix="focus") raise unless self.valid?(ip_address) segments = [prefix] # this ip_address does not need to be encoded as it is a valid # ip_address and only contains key-friendly chars segments << ip_address segments.join('-') end |
Instance Method Details
#country ⇒ Object
32 33 34 |
# File 'lib/focus.rb', line 32 def country @country ||= Country.new(@result) end |
#location ⇒ Object
36 37 38 |
# File 'lib/focus.rb', line 36 def location @location ||= Location.new(@result) end |