Class: Geostats::Cache

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/geostats/models/cache.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from_website(uuid) ⇒ Object



20
21
22
23
24
# File 'lib/geostats/models/cache.rb', line 20

def self.create_from_website(uuid)
  cache = Cache.new(:uuid => uuid)
  cache.update_from_website
  cache
end

Instance Method Details

#update_from_websiteObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/geostats/models/cache.rb', line 26

def update_from_website
  info = Grabber::Cache.new(self.uuid)

  [:name, :code, :size, :latitude, :longitude, :difficulty, :terrain,
   :location, :owner, :hidden_at, :founds_count, :dnf_count
  ].each do |attribute|
    if value = info.send(attribute)
      self.attributes = { attribute => value }
    end
  end

  self.is_pmonly = info.pmonly?
  self.is_archived = info.archived?

  if type = info.type and index = CacheType::MAPPING.index(type)
    self.cache_type = CacheType.where(:id => index + 1).first
  end

  self.synced_at = Time.now
end