Class: GCStats::Caches::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/gcstats/caches.rb

Instance Method Summary collapse

Constructor Details

#initialize(wpt_node) ⇒ Cache

Returns a new instance of Cache.



19
20
21
22
# File 'lib/gcstats/caches.rb', line 19

def initialize(wpt_node)
  @wpt_node = wpt_node
  @cache_node = wpt_node.elements["#{NS}:cache"]
end

Instance Method Details

#archived?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/gcstats/caches.rb', line 54

def archived?
  @archived ||= @cache_node.attributes['archived'].to_s.downcase == 'true'
end

#available?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/gcstats/caches.rb', line 50

def available?
  @available ||= @cache_node.attributes['available'].to_s.downcase == 'true'
end

#codeObject



42
43
44
# File 'lib/gcstats/caches.rb', line 42

def code
  @code ||= @wpt_node.elements['name'].text
end

#containerObject Also known as: size



74
75
76
# File 'lib/gcstats/caches.rb', line 74

def container
  @container ||= @cache_node.elements["#{NS}:container"].text
end

#countryObject



88
89
90
# File 'lib/gcstats/caches.rb', line 88

def country
  @country ||= @cache_node.elements["#{NS}:country"].text
end

#difficultyObject



80
81
82
# File 'lib/gcstats/caches.rb', line 80

def difficulty
  @difficulty ||= @cache_node.elements["#{NS}:difficulty"].text.to_f
end

#find_datesObject



108
109
110
111
112
# File 'lib/gcstats/caches.rb', line 108

def find_dates
  @find_dates ||= begin
    logs.select {|log| log.found? }.map {|log| log.date }
  end
end

#latObject Also known as: latitude



24
25
26
# File 'lib/gcstats/caches.rb', line 24

def lat
  @lat ||= @wpt_node.attributes['lat'].to_f
end

#logsObject



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/gcstats/caches.rb', line 96

def logs
  @logs ||= begin
    logs = []

    @cache_node.each_element("#{NS}:logs/#{NS}:log") {|log_node|
      logs << Log.new(log_node)
    }

    logs
  end
end

#lonObject Also known as: longitude



30
31
32
# File 'lib/gcstats/caches.rb', line 30

def lon
  @lon ||= @wpt_node.attributes['lon'].to_f
end

#nameObject



58
59
60
# File 'lib/gcstats/caches.rb', line 58

def name
  @name ||= @cache_node.elements["#{NS}:name"].text
end

#ownerObject



62
63
64
# File 'lib/gcstats/caches.rb', line 62

def owner
  @owner ||= @cache_node.elements["#{NS}:owner"].text
end

#placed_byObject



66
67
68
# File 'lib/gcstats/caches.rb', line 66

def placed_by
  @placed_by ||= @cache_node.elements["#{NS}:placed_by"].text
end

#publishedObject Also known as: time



36
37
38
# File 'lib/gcstats/caches.rb', line 36

def published
  @published ||= Time.parse(@wpt_node.elements['time'].text)
end

#stateObject



92
93
94
# File 'lib/gcstats/caches.rb', line 92

def state
  @state ||= @cache_node.elements["#{NS}:state"].text.strip
end

#terrainObject



84
85
86
# File 'lib/gcstats/caches.rb', line 84

def terrain
  @terrain ||= @cache_node.elements["#{NS}:terrain"].text.to_f
end

#typeObject



70
71
72
# File 'lib/gcstats/caches.rb', line 70

def type
  @type ||= @cache_node.elements["#{NS}:type"].text
end

#urlObject



46
47
48
# File 'lib/gcstats/caches.rb', line 46

def url
  @url ||= @wpt_node.elements['url'].text
end