Skip to content
Browse files

Added ability to fetch multiple journeys

  • Loading branch information...
1 parent 0ae4053 commit 3303ad91cd6b0cac15c5587a38344a1c12315996 @chendo committed Jan 5, 2012
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/metlinkr.rb
View
15 lib/metlinkr.rb
@@ -12,7 +12,7 @@ def initialize
end
- def route(from, to, options = {:methods => :all})
+ def route(from, to, options = {:methods => :all, :ignore_earlier_journey => true, :limit => 1})
agent = Mechanize.new
agent.user_agent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; chromeframe/12.0.742.112)'
page = agent.get(START_URL)
@@ -41,13 +41,16 @@ def route(from, to, options = {:methods => :all})
doc = Nokogiri::HTML(body)
- link = doc.search('tr.p4 td.dontprint a').first
+ links = doc.search('tr.p4 td.dontprint a, tr.p2 td.dontprint a')
- href = link.attributes['href'].value
+ links.shift if options[:ignore_earlier_journey]
- body = agent.get(href).body
-
- Journey.parse(body)
+ links = links.slice(0, options[:limit])
+ links.map do |link|
+ href = link.attributes['href'].value
+ body = agent.get(href).body
+ Journey.parse(body)
+ end
end
private

0 comments on commit 3303ad9

Please sign in to comment.
Something went wrong with that request. Please try again.