Class: Geocoder::Result::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/geocoder/results/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Base

Takes a hash of data from a parsed geocoding service response.



15
16
17
18
# File 'lib/geocoder/results/base.rb', line 15

def initialize(data)
  @data = data
  @cache_hit = nil
end

Instance Attribute Details

#cache_hitObject

true if result came from cache, false if from request to geocoding service; nil if cache is not configured



10
11
12
# File 'lib/geocoder/results/base.rb', line 10

def cache_hit
  @cache_hit
end

#dataObject

data (hash) fetched from geocoding service



6
7
8
# File 'lib/geocoder/results/base.rb', line 6

def data
  @data
end

Instance Method Details

#address(format = :full) ⇒ Object

A string in the given format.



23
24
25
# File 'lib/geocoder/results/base.rb', line 23

def address(format = :full)
  fail
end

#coordinatesObject

A two-element array: [lat, lon].



30
31
32
# File 'lib/geocoder/results/base.rb', line 30

def coordinates
  [@data['latitude'].to_f, @data['longitude'].to_f]
end

#countryObject



58
59
60
# File 'lib/geocoder/results/base.rb', line 58

def country
  fail
end

#country_codeObject



62
63
64
# File 'lib/geocoder/results/base.rb', line 62

def country_code
  fail
end

#latitudeObject



34
35
36
# File 'lib/geocoder/results/base.rb', line 34

def latitude
  coordinates[0]
end

#longitudeObject



38
39
40
# File 'lib/geocoder/results/base.rb', line 38

def longitude
  coordinates[1]
end

#provinceObject



46
47
48
# File 'lib/geocoder/results/base.rb', line 46

def province
  state
end

#province_codeObject



54
55
56
# File 'lib/geocoder/results/base.rb', line 54

def province_code
  state_code
end

#stateObject



42
43
44
# File 'lib/geocoder/results/base.rb', line 42

def state
  fail
end

#state_codeObject



50
51
52
# File 'lib/geocoder/results/base.rb', line 50

def state_code
  fail
end