Class: Pipl::API::Response::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/pipl/api/response/location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Location

Returns a new instance of Location.



8
9
10
11
12
13
14
15
16
17
# File 'lib/pipl/api/response/location.rb', line 8

def initialize(location)
  @code = location["country"]
  if location["display"] && location["display"].include?(",")
    @state = location["display"].split(", ").first
    @country = location["display"].split(", ").last
  else
    @country = location["display"]
  end
  @estimation = location["estimated_percent"].to_f / 100
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/pipl/api/response/location.rb', line 5

def code
  @code
end

#countryObject (readonly)

Returns the value of attribute country.



5
6
7
# File 'lib/pipl/api/response/location.rb', line 5

def country
  @country
end

#estimationObject (readonly)

Returns the value of attribute estimation.



6
7
8
# File 'lib/pipl/api/response/location.rb', line 6

def estimation
  @estimation
end

#stateObject (readonly)

Returns the value of attribute state.



5
6
7
# File 'lib/pipl/api/response/location.rb', line 5

def state
  @state
end

Instance Method Details

#to_hashObject Also known as: to_h



19
20
21
22
23
24
25
26
# File 'lib/pipl/api/response/location.rb', line 19

def to_hash
  {
    code: code,
    state: state,
    country: country,
    estimation: estimation
  }
end