Class: Metlinkr::Journey
- Inherits:
-
Object
- Object
- Metlinkr::Journey
- Defined in:
- lib/metlinkr/journey.rb
Constant Summary collapse
- START_URL =
"http://jp.metlinkmelbourne.com.au/metlink/XSLT_TRIP_REQUEST2?language=en&itdLPxx_view=advanced"
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#trips ⇒ Object
readonly
Returns the value of attribute trips.
Instance Method Summary collapse
-
#initialize(from, to, options = nil) ⇒ Journey
constructor
A new instance of Journey.
- #plan ⇒ Object
Constructor Details
#initialize(from, to, options = nil) ⇒ Journey
Returns a new instance of Journey.
12 13 14 15 16 |
# File 'lib/metlinkr/journey.rb', line 12 def initialize(from, to, = nil) @from = from @to = to @options = || {:methods => :all, :ignore_earlier_trip => true, :limit => 1} end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
10 11 12 |
# File 'lib/metlinkr/journey.rb', line 10 def from @from end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/metlinkr/journey.rb', line 10 def @options end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
10 11 12 |
# File 'lib/metlinkr/journey.rb', line 10 def to @to end |
#trips ⇒ Object (readonly)
Returns the value of attribute trips.
10 11 12 |
# File 'lib/metlinkr/journey.rb', line 10 def trips @trips end |
Instance Method Details
#plan ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/metlinkr/journey.rb', line 18 def plan 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) f = page.form('tripRequest') # Shitty hack for forcing address f.anyObjFilter_origin = 29 f.execIdentifiedLoc_origin = 1 f.execStopList_origin = 0 f.anyObjFilter_destination = 29 f.execIdentifiedLoc_destination = 1 f.execStopList_destination = 0 f.name_origin = from f.name_destination = to select_methods(f, [:methods]) results = f. body = results.body doc = Nokogiri::HTML(body) links = doc.search('tr.p4 td.dontprint a, tr.p2 td.dontprint a') links.shift if [:ignore_earlier_trip] links = links.slice(0, [:limit]) @trips = links.map do |link| href = link.attributes['href'].value fetch_and_parse_trip_from_href(agent, href) end end |