Class: Translink::Page::Timetable
- Inherits:
-
Translink::Page
- Object
- Translink::Page
- Translink::Page::Timetable
- Defined in:
- lib/translink/page/timetable.rb
Constant Summary
Constants inherited from Translink::Page
Instance Attribute Summary
Attributes inherited from Translink::Page
Instance Method Summary collapse
-
#route_pages(url = nil, step = nil) ⇒ Array<Page::Route>
Builds an unique array of route pages.
-
#timetable_page(timestamp) ⇒ Timetable
Returns a timetable page with routes running on the given date.
Methods inherited from Translink::Page
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.
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.
26 27 28 29 30 31 32 33 |
# File 'lib/translink/page/timetable.rb', line 26 def form = page.forms[1] value = .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 |