Class: Geostats::Grabber::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/geostats/grabber/cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(uuid) ⇒ Cache

Returns a new instance of Cache.



4
5
6
# File 'lib/geostats/grabber/cache.rb', line 4

def initialize(uuid)
  @resp, @data = HTTP.get("/seek/cache_details.aspx?guid=#{uuid}&log=y")
end

Instance Method Details

#archived?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/geostats/grabber/cache.rb', line 86

def archived?
  !!(@data =~ /<li>This cache has been archived/)
end

#codeObject



8
9
10
11
12
# File 'lib/geostats/grabber/cache.rb', line 8

def code
  if @data =~ /<div id="ctl00_cacheCodeWidget".*?>\s*<p>\s*([A-Z0-9]+)<\/p>\s*<\/div>/
    $1
  end
end

#difficultyObject



48
49
50
51
52
# File 'lib/geostats/grabber/cache.rb', line 48

def difficulty
  if @data =~ /<span id="ctl00_ContentBody_Difficulty"><img src=".*?" alt="([0-9\.]+) out of 5" \/><\/span>/
    $1.to_f
  end
end

#dnf_countObject



82
83
84
# File 'lib/geostats/grabber/cache.rb', line 82

def dnf_count
  @data.scan(/<strong><img src=".*?icon_sad\.gif" alt="" \/>&nbsp;/).length
end

#founds_countObject



78
79
80
# File 'lib/geostats/grabber/cache.rb', line 78

def founds_count
  @data.scan(/<strong><img src=".*?icon_smile\.gif" alt="" \/>&nbsp;/).length
end

#hidden_atObject



27
28
29
30
31
# File 'lib/geostats/grabber/cache.rb', line 27

def hidden_at
  if @data =~ /<span id="ctl00_ContentBody_DateHidden">(\d{1,2})\/(\d{1,2})\/(\d{4})<\/span>/
    Time.parse([$2, $1, $3].join("."))
  end
end

#latitudeObject



60
61
62
63
64
# File 'lib/geostats/grabber/cache.rb', line 60

def latitude
  if @data =~ /\/wpt\/\?lat=(.*)&amp;lon=(.*)&amp;detail=1/
    $1.to_f
  end
end

#locationObject



72
73
74
75
76
# File 'lib/geostats/grabber/cache.rb', line 72

def location
  if @data =~ /<span id="ctl00_ContentBody_Location">In (.*?)<\/span>/
    $1
  end
end

#longitudeObject



66
67
68
69
70
# File 'lib/geostats/grabber/cache.rb', line 66

def longitude
  if @data =~ /\/wpt\/\?lat=(.*)&amp;lon=(.*)&amp;detail=1/
    $2.to_f
  end
end

#nameObject



14
15
16
17
18
19
# File 'lib/geostats/grabber/cache.rb', line 14

def name
  if @data =~ /<span id="ctl00_ContentBody_CacheName">(.*?)<\/span>/
    name = Utils.unescape($1)
    name =~ /^<strike>(.*)<\/strike>$/ ? $1 : name
  end
end

#ownerObject



39
40
41
42
43
44
45
46
# File 'lib/geostats/grabber/cache.rb', line 39

def owner
  if @data =~ /<span id="ctl00_ContentBody_CacheOwner">by.*?\/profile\/\?guid=(.*?)&wid=.*<\/a><\/span>/
    user = Grabber::User.new($1)
    if name = user.username
      name
    end
  end
end

#pmonly?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/geostats/grabber/cache.rb', line 90

def pmonly?
  !!(@data =~ /<p class="Warning">Sorry, the owner of this listing has made it viewable to Premium Members only./)
end

#sizeObject



33
34
35
36
37
# File 'lib/geostats/grabber/cache.rb', line 33

def size
  if @data =~ /<img src="\/images\/icons\/container\/(.*?)\.gif" alt="Size: .*?" \/>/
    $1 if %w(micro small regular large other not_chosen).include?($1)
  end
end

#terrainObject



54
55
56
57
58
# File 'lib/geostats/grabber/cache.rb', line 54

def terrain
  if @data =~ /<span id="ctl00_ContentBody_Terrain"><img src=".*?" alt="([0-9\.]+) out of 5" \/><\/span>/
    $1.to_f
  end
end

#typeObject



21
22
23
24
25
# File 'lib/geostats/grabber/cache.rb', line 21

def type
  if @data =~ /<h2.*?WptTypes\/(\d+)\.gif".*?h2>/
    $1.to_i
  end
end