Class: Translink::Page::Timetable

Inherits:
Translink::Page show all
Defined in:
lib/translink/page/timetable.rb

Constant Summary

Constants inherited from Translink::Page

USER_AGENT

Instance Attribute Summary

Attributes inherited from Translink::Page

#agent, #page, #url

Instance Method Summary collapse

Methods inherited from Translink::Page

#initialize

Constructor Details

This class inherits a constructor from Translink::Page

Instance Method Details

#route_pages(url = nil, step = nil) ⇒ Array<Page::Route>

Builds an unique array of route pages.

Parameters:

  • url (URI) (defaults to: nil)

    Omit routes before the route with url.

Returns:



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/translink/page/timetable.rb', line 7

def route_pages url = nil, step = nil
  routes = page.search('table tr td:last-child a').reduce(Array.new) do |routes, anchor|
    route     = Route.new url_from_href(anchor['href']), anchor.text
    duplicate = routes.find { |duplicate| duplicate.url == route.url }
    routes << route unless duplicate
    routes
  end
  if url
    routes.drop_while { |route| route.url != url }.slice 0..(step || routes.size)
  else
    routes
  end
end

#timetable_page(timestamp) ⇒ Timetable

Returns a timetable page with routes running on the given date.

Parameters:

  • timestamp (DateTime)

    Filter by this date. TZ should be Australia/Brisbane and the time should be at midnight.

Returns:



26
27
28
29
30
31
32
33
# File 'lib/translink/page/timetable.rb', line 26

def timetable_page timestamp
  form  = page.forms[1]
  value = timestamp.strftime('%-d/%m/%y %I:%M:%S %p') # Eg: "4/06/2012 12:00:00 AM"
  form.field_with(:name => 'Date').value = value
  self.class.new(url_from_href(form.action)).tap do |page|
    page.page = form.submit
  end
end