geocaching 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +6 -0
- data/geocaching.gemspec +3 -1
- data/lib/geocaching.rb +4 -1
- data/lib/geocaching/cache.rb +65 -21
- data/lib/geocaching/cache_type.rb +57 -13
- data/lib/geocaching/log.rb +34 -2
- data/lib/geocaching/log_type.rb +57 -19
- data/lib/geocaching/my_logs.rb +150 -0
- data/lib/geocaching/user.rb +251 -0
- data/lib/geocaching/version.rb +3 -0
- data/spec/cache/ape.rb +69 -0
- data/spec/cache/cito.rb +12 -0
- data/spec/cache/earthcache.rb +12 -0
- data/spec/cache/event.rb +12 -0
- data/spec/cache/letterbox.rb +12 -0
- data/spec/cache/lfevent.rb +12 -0
- data/spec/cache/locationless.rb +12 -0
- data/spec/cache/megaevent.rb +12 -0
- data/spec/cache/multi.rb +27 -15
- data/spec/cache/mystery.rb +12 -0
- data/spec/cache/traditional.rb +12 -0
- data/spec/cache/virtual.rb +12 -0
- data/spec/cache/webcam.rb +12 -0
- data/spec/cache/wherigo.rb +12 -0
- data/spec/cache_spec.rb +3 -2
- data/spec/log/announcement.rb +28 -0
- data/spec/log/announcement.txt +14 -0
- data/spec/log/archive.rb +28 -0
- data/spec/log/archive.txt +5 -0
- data/spec/log/attended.rb +28 -0
- data/spec/log/attended.txt +1 -0
- data/spec/log/coords_update.rb +28 -0
- data/spec/log/coords_update.txt +9 -0
- data/spec/log/disable.rb +28 -0
- data/spec/log/disable.txt +3 -0
- data/spec/log/dnf.rb +28 -0
- data/spec/log/dnf.txt +5 -0
- data/spec/log/enable.rb +28 -0
- data/spec/log/enable.txt +1 -0
- data/spec/log/found.rb +28 -0
- data/spec/{log_message.txt → log/found.txt} +0 -0
- data/spec/log/needs_archived.rb +28 -0
- data/spec/log/needs_archived.txt +1 -0
- data/spec/log/needs_maintenance.rb +28 -0
- data/spec/log/needs_maintenance.txt +1 -0
- data/spec/log/note.rb +28 -0
- data/spec/log/note.txt +1 -0
- data/spec/log/owner_maintenance.rb +28 -0
- data/spec/log/owner_maintenance.txt +1 -0
- data/spec/log/publish.rb +28 -0
- data/spec/log/publish.txt +1 -0
- data/spec/log/retract.rb +28 -0
- data/spec/log/retract.txt +4 -0
- data/spec/log/reviewer_note.rb +28 -0
- data/spec/log/reviewer_note.txt +3 -0
- data/spec/log/unarchive.rb +28 -0
- data/spec/log/unarchive.txt +1 -0
- data/spec/log/webcam_photo_taken.rb +28 -0
- data/spec/log/webcam_photo_taken.txt +1 -0
- data/spec/log/will_attend.rb +28 -0
- data/spec/log/will_attend.txt +1 -0
- data/spec/log_spec.rb +7 -17
- data/spec/user_spec.rb +48 -0
- metadata +44 -6
- data/lib/geocaching/mylogs.rb +0 -63
data/README.markdown
CHANGED
@@ -5,6 +5,12 @@ This Ruby library provides an API for geocaching.com. As Groundspeak
|
|
5
5
|
doesn’t offer an official API yet, this library parses the website’s
|
6
6
|
HTML code.
|
7
7
|
|
8
|
+
Documentation
|
9
|
+
-------------
|
10
|
+
|
11
|
+
Documentation is available at
|
12
|
+
[rdoc.info](http://rdoc.info/projects/nano/ruby-geocaching).
|
13
|
+
|
8
14
|
Example
|
9
15
|
-------
|
10
16
|
|
data/geocaching.gemspec
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/lib/geocaching/version"
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.name = "geocaching"
|
3
|
-
s.version =
|
5
|
+
s.version = Geocaching::VERSION
|
4
6
|
|
5
7
|
s.summary = "Ruby API for geocaching.com"
|
6
8
|
s.description = "A Ruby library that provides an API for geocaching.com"
|
data/lib/geocaching.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require "nokogiri"
|
4
|
+
require "geocaching/version"
|
4
5
|
|
5
6
|
# This is a Ruby library to access information on geocaching.com. As
|
6
7
|
# Groundspeak does not provide a public API yet, one needs to parse the
|
@@ -71,5 +72,7 @@ module Geocaching
|
|
71
72
|
autoload :Cache, "geocaching/cache"
|
72
73
|
autoload :CacheType, "geocaching/cache_type"
|
73
74
|
autoload :Log, "geocaching/log"
|
74
|
-
autoload :
|
75
|
+
autoload :LogType, "geocaching/log_type"
|
76
|
+
autoload :MyLogs, "geocaching/my_logs"
|
77
|
+
autoload :User, "geocaching/user"
|
75
78
|
end
|
data/lib/geocaching/cache.rb
CHANGED
@@ -29,7 +29,7 @@ module Geocaching
|
|
29
29
|
# puts cache.archived? #=> false
|
30
30
|
#
|
31
31
|
class Cache
|
32
|
-
#
|
32
|
+
# Create a new instance and call the {#fetch} methods afterwards.
|
33
33
|
# One of +:code+ or +:guid+ must be provided as attributes.
|
34
34
|
#
|
35
35
|
# @param [Hash] attributes A hash of attributes, see {#initialize}
|
@@ -42,7 +42,7 @@ module Geocaching
|
|
42
42
|
cache
|
43
43
|
end
|
44
44
|
|
45
|
-
#
|
45
|
+
# Create a new instance. The following attributes may be specified
|
46
46
|
# as parameters:
|
47
47
|
#
|
48
48
|
# * +:code+ — The cache’s GC code
|
@@ -54,7 +54,11 @@ module Geocaching
|
|
54
54
|
@data, @doc, @code, @guid = nil, nil, nil, nil
|
55
55
|
|
56
56
|
attributes.each do |key, value|
|
57
|
-
if [:code, :guid].include?(key)
|
57
|
+
if [:code, :guid, :name, :type].include?(key)
|
58
|
+
if key == :type and not value.kind_of?(CacheType)
|
59
|
+
raise TypeError, "Attribute `type' must be an instance of Geocaching::CacheType"
|
60
|
+
end
|
61
|
+
|
58
62
|
instance_variable_set("@#{key}", value)
|
59
63
|
else
|
60
64
|
raise ArgumentError, "Trying to set unknown attribute `#{key}'"
|
@@ -62,7 +66,7 @@ module Geocaching
|
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
65
|
-
#
|
69
|
+
# Fetche cache information from geocaching.com.
|
66
70
|
#
|
67
71
|
# @return [void]
|
68
72
|
# @raise [ArgumentError] Neither code nor GUID are given
|
@@ -75,7 +79,7 @@ module Geocaching
|
|
75
79
|
@doc = Nokogiri::HTML.parse(@data)
|
76
80
|
end
|
77
81
|
|
78
|
-
#
|
82
|
+
# Return whether information have successfully been fetched
|
79
83
|
# from geocaching.com.
|
80
84
|
#
|
81
85
|
# @return [Boolean] Have information been fetched?
|
@@ -83,7 +87,7 @@ module Geocaching
|
|
83
87
|
@data and @doc
|
84
88
|
end
|
85
89
|
|
86
|
-
#
|
90
|
+
# Return the cache’s code (GCXXXXXX).
|
87
91
|
#
|
88
92
|
# @return [String] Code
|
89
93
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -101,7 +105,7 @@ module Geocaching
|
|
101
105
|
end
|
102
106
|
end
|
103
107
|
|
104
|
-
#
|
108
|
+
# Return the cache’s Globally Unique Identifier (GUID).
|
105
109
|
#
|
106
110
|
# @return [String] GUID
|
107
111
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -123,7 +127,7 @@ module Geocaching
|
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
126
|
-
#
|
130
|
+
# Return the cache’s type ID.
|
127
131
|
#
|
128
132
|
# @return [Fixnum] Type ID
|
129
133
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -140,7 +144,7 @@ module Geocaching
|
|
140
144
|
end
|
141
145
|
end
|
142
146
|
|
143
|
-
#
|
147
|
+
# Return the cache’s type.
|
144
148
|
#
|
145
149
|
# @return [Geocaching::CacheType] Type
|
146
150
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -149,7 +153,7 @@ module Geocaching
|
|
149
153
|
@type ||= CacheType.for_id(type_id)
|
150
154
|
end
|
151
155
|
|
152
|
-
#
|
156
|
+
# Return the cache’s name.
|
153
157
|
#
|
154
158
|
# @return [String] Name
|
155
159
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -167,7 +171,35 @@ module Geocaching
|
|
167
171
|
end
|
168
172
|
end
|
169
173
|
|
170
|
-
#
|
174
|
+
# Return the cache’s owner.
|
175
|
+
#
|
176
|
+
# @return [Geocaching::User]
|
177
|
+
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
178
|
+
# @raise [Geocaching::ExtractError] Could not extract info from website"
|
179
|
+
def owner
|
180
|
+
@owner ||= begin
|
181
|
+
raise NotFetchedError unless fetched?
|
182
|
+
|
183
|
+
if @data =~ /<strong>\s*?A[(n\s*?Event)]*\s*?cache\s*?<\/strong>\s*?by\s*?<a.*?guid=([a-f0-9-]{36}).*?>(.*?)<\/a>/
|
184
|
+
@owner_display_name = HTTP.unescape($2)
|
185
|
+
User.new(:guid => $1)
|
186
|
+
else
|
187
|
+
raise ExtractError, "Could not extract owner from website"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Return the displayed cache owner name.
|
193
|
+
#
|
194
|
+
# @return [String]
|
195
|
+
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
196
|
+
# @raise [Geocaching::ExtractError] Could not extract info from website"
|
197
|
+
def owner_display_name
|
198
|
+
owner unless @owner_display_name
|
199
|
+
@owner_display_name
|
200
|
+
end
|
201
|
+
|
202
|
+
# Return the cache’s difficulty rating.
|
171
203
|
#
|
172
204
|
# @return [Float] Difficulty rating
|
173
205
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -184,7 +216,7 @@ module Geocaching
|
|
184
216
|
end
|
185
217
|
end
|
186
218
|
|
187
|
-
#
|
219
|
+
# Return the cache’s terrain rating.
|
188
220
|
#
|
189
221
|
# @return [Float] Terrain rating
|
190
222
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -201,7 +233,7 @@ module Geocaching
|
|
201
233
|
end
|
202
234
|
end
|
203
235
|
|
204
|
-
#
|
236
|
+
# Return the date the cache has been hidden at.
|
205
237
|
#
|
206
238
|
# @return [Time] Hidden date
|
207
239
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -218,7 +250,7 @@ module Geocaching
|
|
218
250
|
end
|
219
251
|
end
|
220
252
|
|
221
|
-
#
|
253
|
+
# Return the date the event has been held.
|
222
254
|
#
|
223
255
|
# @return [Time] Event date
|
224
256
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -236,7 +268,7 @@ module Geocaching
|
|
236
268
|
end
|
237
269
|
end
|
238
270
|
|
239
|
-
#
|
271
|
+
# Return the cache’s container size.
|
240
272
|
#
|
241
273
|
# @return [Symbol] Cache container size
|
242
274
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -256,7 +288,7 @@ module Geocaching
|
|
256
288
|
end
|
257
289
|
end
|
258
290
|
|
259
|
-
#
|
291
|
+
# Return the cache’s latitude.
|
260
292
|
#
|
261
293
|
# @return [Float] Latitude
|
262
294
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -279,7 +311,7 @@ module Geocaching
|
|
279
311
|
end
|
280
312
|
end
|
281
313
|
|
282
|
-
#
|
314
|
+
# Return the cache’s longitude.
|
283
315
|
#
|
284
316
|
# @return [Float] Longitude
|
285
317
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -302,7 +334,7 @@ module Geocaching
|
|
302
334
|
end
|
303
335
|
end
|
304
336
|
|
305
|
-
#
|
337
|
+
# Return the cache’s location name (State, Country).
|
306
338
|
#
|
307
339
|
# @return [String] Location name
|
308
340
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -326,7 +358,7 @@ module Geocaching
|
|
326
358
|
end
|
327
359
|
end
|
328
360
|
|
329
|
-
#
|
361
|
+
# Return whether the cache has been archived or not.
|
330
362
|
#
|
331
363
|
# @return [Boolean] Has cache been archived?
|
332
364
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -337,7 +369,7 @@ module Geocaching
|
|
337
369
|
end
|
338
370
|
end
|
339
371
|
|
340
|
-
#
|
372
|
+
# Return whether the cache is only viewable to Premium Member only.
|
341
373
|
#
|
342
374
|
# @return [Boolean] Is cache PM-only?
|
343
375
|
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
@@ -350,7 +382,19 @@ module Geocaching
|
|
350
382
|
end
|
351
383
|
end
|
352
384
|
|
353
|
-
#
|
385
|
+
# Return whether the cache is currently in review.
|
386
|
+
#
|
387
|
+
# @return [Boolean] Is cache currently in review?
|
388
|
+
# @raise [Geocaching::NotFetchedError] Need to call {#fetch} first
|
389
|
+
def in_review?
|
390
|
+
@in_review ||= begin
|
391
|
+
raise NotFetchedError unless fetched?
|
392
|
+
[!!@data.match(/<p class="Warning">Sorry, you cannot view this cache listing until it has been published/),
|
393
|
+
!!@data.match(/<p class="Warning">This cache listing has not been reviewed yet/)].any?
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
# Return an array of logs for this cache. A log is an instance of
|
354
398
|
# {Geocaching::Log}.
|
355
399
|
#
|
356
400
|
# @return [Geocaching::LogsArray<Geocaching::Log>] Array of logs
|
@@ -1,44 +1,88 @@
|
|
1
1
|
module Geocaching
|
2
|
+
# This class represents a cache type.
|
3
|
+
#
|
4
|
+
# if @cache.type == :traditional
|
5
|
+
# puts "Cache is a Traditional Cache"
|
6
|
+
# end
|
2
7
|
class CacheType
|
8
|
+
# A mapping of cache types to their corresponding ID and name
|
9
|
+
# on geocaching.com.
|
3
10
|
TYPES = {
|
4
|
-
:traditional => [2,
|
5
|
-
:multi => [3,
|
6
|
-
:mystery => [8,
|
7
|
-
:letterbox => [5,
|
8
|
-
:wherigo => [1858, "Wherigo"],
|
9
|
-
:event => [6,
|
10
|
-
:megaevent => [453,
|
11
|
-
:cito => [13,
|
12
|
-
:earthcache => [137,
|
11
|
+
:traditional => [2, "Traditional Cache"],
|
12
|
+
:multi => [3, "Multi-cache"],
|
13
|
+
:mystery => [8, "Unknown Cache"],
|
14
|
+
:letterbox => [5, "Letterbox Hybrid"],
|
15
|
+
:wherigo => [1858, "Wherigo Cache"],
|
16
|
+
:event => [6, "Event Cache"],
|
17
|
+
:megaevent => [453, "Mega-Event Cache"],
|
18
|
+
:cito => [13, "Cache In Trash Out Event"],
|
19
|
+
:earthcache => [137, "Earthcache"],
|
13
20
|
:lfevent => [3653, "Lost and Found Event Cache"],
|
14
|
-
:locationless => [12,
|
15
|
-
:webcam => [11,
|
16
|
-
:virtual => [4,
|
17
|
-
:ape => [
|
21
|
+
:locationless => [12, "Locationless (Reverse) Cache"],
|
22
|
+
:webcam => [11, "Webcam Cache"],
|
23
|
+
:virtual => [4, "Virtual Cache"],
|
24
|
+
:ape => [9, "Project APE Cache"]
|
18
25
|
}
|
19
26
|
|
27
|
+
# Return a {CacheType} object for the given cache type id, or
|
28
|
+
# nil if no appropriate cache id is found.
|
29
|
+
#
|
30
|
+
# @return [Geocaching::CacheType]
|
31
|
+
# @return [nil] If no appropriate cache type is found
|
20
32
|
def self.for_id(id)
|
21
33
|
if info = TYPES.to_a.select { |(k,v)| v[0] == id } and info.size == 1
|
22
34
|
new(info.first)
|
23
35
|
end
|
24
36
|
end
|
25
37
|
|
38
|
+
# Return a {CacheType} object for the given cache type title, or
|
39
|
+
# nil if no appropriate cache type is found.
|
40
|
+
#
|
41
|
+
# @return [Geocaching::CacheType]
|
42
|
+
# @return [nil] If no appropriate cache type is found
|
43
|
+
def self.for_title(title)
|
44
|
+
if info = TYPES.to_a.select { |(k,v)| v[1] == title } and info.size == 1
|
45
|
+
new(info.first)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Create a new instance. You should not need to create an instance
|
50
|
+
# of this class on your own. Use {for_id} and {for_title}.
|
26
51
|
def initialize(info)
|
27
52
|
@info = info
|
28
53
|
end
|
29
54
|
|
55
|
+
# Return the cache type’s ID.
|
56
|
+
#
|
57
|
+
# @return [Fixnum]
|
30
58
|
def id
|
31
59
|
@info[1][0]
|
32
60
|
end
|
33
61
|
|
62
|
+
# Return the cache type’s name.
|
63
|
+
#
|
64
|
+
# @return [String]
|
34
65
|
def name
|
35
66
|
@info[1][1]
|
36
67
|
end
|
37
68
|
|
69
|
+
alias to_s name
|
70
|
+
|
71
|
+
# Return the symbol that describes this cache type. See the {TYPES}
|
72
|
+
# hash for a list of cache type symbols.
|
73
|
+
#
|
74
|
+
# @return [Symbol]
|
38
75
|
def to_sym
|
39
76
|
@info[0]
|
40
77
|
end
|
41
78
|
|
79
|
+
# Overload the == operator.
|
80
|
+
#
|
81
|
+
# if @cache.type == :multi
|
82
|
+
# puts "It's a multi cache."
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# @return [Boolean]
|
42
86
|
def ==(s)
|
43
87
|
to_sym == s
|
44
88
|
end
|
data/lib/geocaching/log.rb
CHANGED
@@ -30,11 +30,15 @@ module Geocaching
|
|
30
30
|
@data, @doc, @guid, @cache = nil, nil, nil, nil
|
31
31
|
|
32
32
|
attributes.each do |key, value|
|
33
|
-
if [:guid, :title, :cache].include?(key)
|
33
|
+
if [:guid, :title, :date, :cache].include?(key)
|
34
34
|
if key == :cache and not value.kind_of?(Geocaching::Cache)
|
35
35
|
raise TypeError, "Attribute `cache' must be an instance of Geocaching::Cache"
|
36
36
|
end
|
37
37
|
|
38
|
+
if key == :date and not value.kind_of?(Time)
|
39
|
+
raise TypeError, "Attribute `type' must be an instance of Time"
|
40
|
+
end
|
41
|
+
|
38
42
|
instance_variable_set("@#{key}", value)
|
39
43
|
else
|
40
44
|
raise ArgumentError, "Trying to set unknown attribute `#{key}'"
|
@@ -76,8 +80,22 @@ module Geocaching
|
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
83
|
+
def type
|
84
|
+
@type ||= LogType.for_title(title)
|
85
|
+
end
|
86
|
+
|
79
87
|
def title
|
80
|
-
@title
|
88
|
+
@title ||= begin
|
89
|
+
raise NotFetchedError unless fetched?
|
90
|
+
|
91
|
+
imgs = @doc.search("#ctl00_ContentBody_LogBookPanel1_LogImage")
|
92
|
+
|
93
|
+
unless imgs.size == 1 and imgs.first["alt"]
|
94
|
+
raise ExtractError, "Could not extract title from website"
|
95
|
+
end
|
96
|
+
|
97
|
+
imgs.first["alt"]
|
98
|
+
end
|
81
99
|
end
|
82
100
|
|
83
101
|
# The name of the user that has posted this log.
|
@@ -99,6 +117,20 @@ module Geocaching
|
|
99
117
|
end
|
100
118
|
end
|
101
119
|
|
120
|
+
def date
|
121
|
+
@date ||= begin
|
122
|
+
raise NotFetchedError unless fetched?
|
123
|
+
|
124
|
+
elements = @doc.search("#ctl00_ContentBody_LogBookPanel1_LogDate")
|
125
|
+
|
126
|
+
if elements.size == 1
|
127
|
+
Time.parse(elements.first.content)
|
128
|
+
else
|
129
|
+
raise ExtractError, "Could not extract date from website"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
102
134
|
# The log’s raw message with all format codes.
|
103
135
|
#
|
104
136
|
# @return [String] Log message
|
data/lib/geocaching/log_type.rb
CHANGED
@@ -1,54 +1,92 @@
|
|
1
1
|
module Geocaching
|
2
|
+
# This class represents a log type.
|
3
|
+
#
|
4
|
+
# if @log.type == :archive
|
5
|
+
# puts "#{@log.cache.code} has been archived"
|
6
|
+
# end
|
2
7
|
class LogType
|
8
|
+
# Mapping of log types to their corresponding icon and title
|
9
|
+
# on geocaching.com.
|
3
10
|
TYPES = {
|
4
|
-
:
|
5
|
-
:
|
6
|
-
:dnf => ["icon_sad",
|
7
|
-
:found => ["icon_smile",
|
8
|
-
:webcam_photo_taken => ["", "
|
9
|
-
:will_attend => ["icon_rsvp",
|
10
|
-
:announcement => ["icon_announcement",
|
11
|
-
:attended => ["icon_attended",
|
12
|
-
:needs_maintenance => ["icon_needsmaint",
|
13
|
-
:owner_maintenance => ["icon_maint",
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:note => ["icon_note",
|
17
|
-
:needs_archived => ["icon_remove",
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:reviewer_note => ["big_smile",
|
11
|
+
:publish => ["icon_greenlight", "Publish Listing"],
|
12
|
+
:retract => ["icon_redlight", "Retract Listing"],
|
13
|
+
:dnf => ["icon_sad", "Didn't find it"],
|
14
|
+
:found => ["icon_smile", "Found it"],
|
15
|
+
:webcam_photo_taken => ["icon_camera", "Webcam Photo Taken"],
|
16
|
+
:will_attend => ["icon_rsvp", "Will Attend"],
|
17
|
+
:announcement => ["icon_announcement", "Announcement"],
|
18
|
+
:attended => ["icon_attended", "Attended"],
|
19
|
+
:needs_maintenance => ["icon_needsmaint", "Needs Maintenance"],
|
20
|
+
:owner_maintenance => ["icon_maint", "Owner Maintenance"],
|
21
|
+
:disable => ["icon_disabled", "Temporarily Disable Listing"],
|
22
|
+
:enable => ["icon_enabled", "Enable Listing"],
|
23
|
+
:note => ["icon_note", "Write note"],
|
24
|
+
:needs_archived => ["icon_remove", "Needs Archived"],
|
25
|
+
:archive => ["traffic_cone", "Archive"],
|
26
|
+
:unarchive => ["traffic_cone", "Unarchive"],
|
27
|
+
:coords_update => ["coord_update", "Update Coordinates"],
|
28
|
+
:reviewer_note => ["big_smile", "Post Reviewer Note"]
|
22
29
|
}
|
23
30
|
|
31
|
+
# Return a {LogType} object for the given log type icon, or nil if
|
32
|
+
# no appropriate log type is found.
|
33
|
+
#
|
34
|
+
# @return [Geocaching::LogType]
|
35
|
+
# @return [nil] If no appropriate log type is found
|
24
36
|
def self.for_icon(icon)
|
25
37
|
if info = TYPES.to_a.select { |(k,v)| v[0] == icon } and info.size == 1
|
26
38
|
new(info.first)
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
42
|
+
# Return a {LogType} object for the given log type title, or nil if
|
43
|
+
# no appropriate log type is found.
|
44
|
+
#
|
45
|
+
# @return [Geocaching::LogType]
|
46
|
+
# @return [nil] If no appropriate log type is found
|
30
47
|
def self.for_title(title)
|
31
48
|
if info = TYPES.to_a.select { |(k,v)| v[1] == title } and info.size == 1
|
32
49
|
new(info.first)
|
33
50
|
end
|
34
51
|
end
|
35
52
|
|
36
|
-
|
53
|
+
# Create a new instance. You should not need to create an instance
|
54
|
+
# of this class on your own. Use {for_icon} and {for_title}.
|
55
|
+
def initialize(info)
|
37
56
|
@info = info
|
38
57
|
end
|
39
58
|
|
59
|
+
# Return the log type’s icon.
|
60
|
+
#
|
61
|
+
# @return [String]
|
40
62
|
def icon
|
41
63
|
@info[1][0]
|
42
64
|
end
|
43
65
|
|
66
|
+
# Return the log type’s title.
|
67
|
+
#
|
68
|
+
# @return [String]
|
44
69
|
def description
|
45
70
|
@info[1][1]
|
46
71
|
end
|
47
72
|
|
73
|
+
alias to_s description
|
74
|
+
|
75
|
+
# Return the symbol representatin of the log type. See the {TYPES}
|
76
|
+
# hash for a list of log type symbols.
|
77
|
+
#
|
78
|
+
# @return [Symbol]
|
48
79
|
def to_sym
|
49
80
|
@info[0]
|
50
81
|
end
|
51
82
|
|
83
|
+
# Overload the == operator.
|
84
|
+
#
|
85
|
+
# if @log.type == :dnf
|
86
|
+
# puts "Someone could not find the cache"
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# @return [Boolean]
|
52
90
|
def ==(s)
|
53
91
|
to_sym == s
|
54
92
|
end
|