Class: Locator

Inherits:
Object
  • Object
show all
Defined in:
lib/meteorologist/locator.rb

Constant Summary collapse

GEOCODE_URL =
'https://maps.googleapis.com/maps/api/geocode'

Instance Method Summary collapse

Constructor Details

#initialize(location, options = {}) ⇒ Locator

Returns a new instance of Locator.



5
6
7
8
9
10
# File 'lib/meteorologist/locator.rb', line 5

def initialize(location, options = {})
  data = options.fetch(:data) { get_data_from_api(location) }
  @location = location
  @navigation_data = validate_and_parse(data)
  @cache_class = options.fetch(:cache_class) { LocationCache }
end

Instance Method Details

#coordinatesObject



12
13
14
# File 'lib/meteorologist/locator.rb', line 12

def coordinates
  "#{geometry['location']['lat']},#{geometry['location']['lng']}"
end

#nameObject



16
17
18
# File 'lib/meteorologist/locator.rb', line 16

def name
  navigation_data['formatted_address']
end

#write_to_cacheObject



20
21
22
# File 'lib/meteorologist/locator.rb', line 20

def write_to_cache
  @cache_class.write(location, attributes_for_cache)
end