Class: Google::Result
- Inherits:
-
Object
- Object
- Google::Result
- Defined in:
- lib/google/result.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #accuracy ⇒ Object
- #address ⇒ Object
- #dump ⇒ Object
- #error? ⇒ Boolean
-
#initialize(data) ⇒ Result
constructor
A new instance of Result.
- #latlng ⇒ Object
- #success? ⇒ Boolean
-
#viewport ⇒ Object
returns viewport in tlbr format.
- #viewport_height ⇒ Object
Constructor Details
#initialize(data) ⇒ Result
Returns a new instance of Result.
7 8 9 |
# File 'lib/google/result.rb', line 7 def initialize(data) @data = JSON.parse data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/google/result.rb', line 5 def data @data end |
Instance Method Details
#accuracy ⇒ Object
31 32 33 |
# File 'lib/google/result.rb', line 31 def accuracy data["Placemark"][0]["AddressDetails"]["Accuracy"] end |
#address ⇒ Object
27 28 29 |
# File 'lib/google/result.rb', line 27 def address data["Placemark"][0]["address"] end |
#dump ⇒ Object
19 20 21 |
# File 'lib/google/result.rb', line 19 def dump data.to_yaml end |
#error? ⇒ Boolean
15 16 17 |
# File 'lib/google/result.rb', line 15 def error? !success? end |
#latlng ⇒ Object
23 24 25 |
# File 'lib/google/result.rb', line 23 def latlng data["Placemark"][0]["Point"]["coordinates"][0..1].reverse end |
#success? ⇒ Boolean
11 12 13 |
# File 'lib/google/result.rb', line 11 def success? data["Status"]["code"] == 200 end |
#viewport ⇒ Object
returns viewport in tlbr format
36 37 38 |
# File 'lib/google/result.rb', line 36 def @vp ||= [:north, :west, :south, :east].map {|dir| data["Placemark"][0]["ExtendedData"]["LatLonBox"][dir.to_s] } end |
#viewport_height ⇒ Object
40 41 42 43 |
# File 'lib/google/result.rb', line 40 def vp = vs = (vp[0] - vp[2]) * 67.0 end |