Class: LocationCache

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LocationCache.



8
9
10
# File 'lib/meteorologist/location_cache.rb', line 8

def initialize(location, options = {})
  @location = location.downcase
end

Class Method Details

.write(location, attributes) ⇒ Object



4
5
6
# File 'lib/meteorologist/location_cache.rb', line 4

def self.write(location, attributes)
  new(location).write(attributes)
end

Instance Method Details

#coordinatesObject



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

def coordinates
  cache[location][:coordinates] if exists?
end

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  !cache[location].nil?
end

#nameObject



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

def name
  cache[location][:name] if exists?
end

#write(attributes) ⇒ Object



24
25
26
27
28
29
# File 'lib/meteorologist/location_cache.rb', line 24

def write(attributes)
  validate_required_attributes(attributes)

  cache[location] = attributes
  File.open(cache_full_path, 'w+') { |f| f.write(cache.to_yaml) }
end