Permalink
Browse files

Added argument for specifying which modes of transport

  • Loading branch information...
1 parent 5358789 commit 0ae4053864968c74908f7ada3edf79bc078206c6 @chendo committed Dec 15, 2011
Showing with 30 additions and 4 deletions.
  1. +27 −1 lib/metlinkr.rb
  2. +1 −1 lib/metlinkr/step.rb
  3. +2 −2 metlinkr.gemspec
View
@@ -12,7 +12,7 @@ def initialize
end
- def route(from, to, options = {})
+ def route(from, to, options = {:methods => :all})
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)
@@ -32,6 +32,9 @@ def route(from, to, options = {})
f.name_origin = from
f.name_destination = to
+
+ select_methods(f, options[:methods])
+
results = f.click_button
body = results.body
@@ -47,6 +50,29 @@ def route(from, to, options = {})
Journey.parse(body)
end
+ private
+
+ METHOD_MAPPING = {
+ :train => 'inclMOT_1',
+ :tram => 'inclMOT_4',
+ :bus => 'inclMOT_5',
+ :vline => 'inclMOT_0',
+ :regional_bus => 'inclMOT_6',
+ :skybus => 'inclMOT_3'
+ }
+
+ ALL_METHODS = [:tram, :train, :bus, :vline, :regional_bus, :skybus]
+
+ def select_methods(form, methods = :all)
+ if methods == :all
+ methods = ALL_METHODS
+ end
+
+ (ALL_METHODS - [methods].flatten).each do |method|
+ form.checkbox_with(:name => METHOD_MAPPING[method]).uncheck
+ end
+
+ end
end
$LOAD_PATH << File.dirname(__FILE__)
View
@@ -67,7 +67,7 @@ def parse_duration
end
def clean_stop_name(stop)
- stop.gsub(/^(From Stop)|(Get off at( stop)?)|(To)\b/i, '').gsub(/(\d+)-/, 'Stop \1 - ').gsub(/[^ -z]+/, ' ').strip
+ stop.gsub(/^(From( Stop)?)|(Get off at( stop)?)|(To)\b/i, '').gsub(/(\d+)-/, 'Stop \1 - ').gsub(/[^ -z]+/, ' ').strip
end
def clean_time(time)
View
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
s.authors = ["Jack Chen (chendo)"]
s.email = []
s.homepage = ""
- s.summary = %q{TODO: Write a gem summary}
- s.description = %q{TODO: Write a gem description}
+ s.summary = %q{Web-scrapin' the Metlink journey planner}
+ s.description = %q{A gem to operate the Metlink journey planner}
s.rubyforge_project = "metlinkr"

0 comments on commit 0ae4053

Please sign in to comment.