Class: EarthTools::Result::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/earth_tools/result/base.rb

Overview

The base result object.

Contains shared domain fields. Extended by different results.

Direct Known Subclasses

Height, SunriseSunset, TimeZone

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Base

Takes a hash of result data from a parsed Google result document.

Parameters:

  • the (Object)


15
16
17
# File 'lib/earth_tools/result/base.rb', line 15

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/earth_tools/result/base.rb', line 10

def data
  @data
end

Instance Method Details

#latitudeFloat

Returns:

  • (Float)

    the latitude



30
31
32
# File 'lib/earth_tools/result/base.rb', line 30

def latitude
  @data['location']['latitude'].to_f
end

#locationArray

Get the geographical location

Returns:

  • (Array)

    a two-element array: [latitude, longitude]



22
23
24
# File 'lib/earth_tools/result/base.rb', line 22

def location
  [latitude, longitude]
end

#longitudeObject

Returns:

  • the longitude



38
39
40
# File 'lib/earth_tools/result/base.rb', line 38

def longitude
  @data['location']['longitude'].to_f
end

#versionFloat

The version of the response format

Returns:

  • (Float)

    the version



45
46
47
# File 'lib/earth_tools/result/base.rb', line 45

def version
  @data['version'].to_f
end