Class: Geostats::Grabber::Logs

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

Defined Under Namespace

Classes: Log

Constant Summary collapse

REGEX =
%r{<tr.*?>\s*<td><img src="/images/icons/([a-z_]+)\.gif" width="16" height="16" alt=".*?" /></td>\s*<td>([0-9\/]+)</td>\s*<td><a href="http://www\.geocaching\.com/seek/cache_details\.aspx\?guid=([a-f0-9\-]+)">(.*?)</a>&nbsp;</td>\s*<td>(.*?) &nbsp;</td>\s*<td><a href="http://www\.geocaching\.com/seek/log\.aspx\?LUID=([a-f0-9\-]+)" target="_blank" title="Visit Log">Visit Log</a></td>\s*</tr>}

Instance Method Summary collapse

Constructor Details

#initializeLogs

Returns a new instance of Logs.



10
11
12
# File 'lib/geostats/grabber/logs.rb', line 10

def initialize
  @resp, @data = HTTP.get("/my/logs.aspx?s=1")
end

Instance Method Details

#logsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/geostats/grabber/logs.rb', line 14

def logs
  @data.scan(REGEX).map do |match|
    log             = Log.new

    log.icon        = match[0]
    log.cache_uuid  = match[2]
    log.cache_name  = Utils.unescape(match[3])
    log.location    = Utils.unescape(match[4])
    log.log_uuid    = match[5]
    log.logged_at   = match[1]

    log.cache_name  = Utils.unescape($1) if log.cache_name =~ /^<span class="Strike Warning">(.*)<\/span>$/
    log.cache_name  = Utils.unescape($1) if log.cache_name =~ /^<strike>(.*)<\/strike>$/

    if log.logged_at =~ /^(\d+)\/(\d+)\/(\d+)$/
      log.logged_at = Time.parse([$2, $1, $3].join("."))
    end

    log
  end
end