Class: Google::Result

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/google/result.rb', line 5

def data
  @data
end

Instance Method Details

#accuracyObject



31
32
33
# File 'lib/google/result.rb', line 31

def accuracy
  data["Placemark"][0]["AddressDetails"]["Accuracy"]
end

#addressObject



27
28
29
# File 'lib/google/result.rb', line 27

def address
  data["Placemark"][0]["address"]
end

#dumpObject



19
20
21
# File 'lib/google/result.rb', line 19

def dump
  data.to_yaml
end

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !success?
end

#latlngObject



23
24
25
# File 'lib/google/result.rb', line 23

def latlng
  data["Placemark"][0]["Point"]["coordinates"][0..1].reverse
end

#success?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/google/result.rb', line 11

def success?
  data["Status"]["code"] == 200
end

#viewportObject

returns viewport in tlbr format



36
37
38
# File 'lib/google/result.rb', line 36

def viewport
  @vp ||= [:north, :west, :south, :east].map {|dir| data["Placemark"][0]["ExtendedData"]["LatLonBox"][dir.to_s] }
end

#viewport_heightObject



40
41
42
43
# File 'lib/google/result.rb', line 40

def viewport_height
  vp = viewport
  vs = (vp[0] - vp[2]) * 67.0
end