Class: LocationCache
- Inherits:
-
Object
- Object
- LocationCache
- Defined in:
- lib/meteorologist/location_cache.rb
Class Method Summary collapse
Instance Method Summary collapse
- #coordinates ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(location, options = {}) ⇒ LocationCache
constructor
A new instance of LocationCache.
- #name ⇒ Object
- #write(attributes) ⇒ Object
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, = {}) @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
#coordinates ⇒ Object
16 17 18 |
# File 'lib/meteorologist/location_cache.rb', line 16 def coordinates cache[location][:coordinates] if exists? end |
#exists? ⇒ Boolean
12 13 14 |
# File 'lib/meteorologist/location_cache.rb', line 12 def exists? !cache[location].nil? end |
#name ⇒ Object
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 |