Class: Bahn::Route
- Inherits:
-
Object
- Object
- Bahn::Route
- Includes:
- ActionView::Helpers::DateHelper
- Defined in:
- lib/bahn/bahn_route.rb
Overview
Feel free to refactor ;)
Instance Attribute Summary collapse
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#price ⇒ Object
Returns the value of attribute price.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#end_time ⇒ Object
End time of the route.
-
#end_time_from_now ⇒ Object
End time from now in words.
-
#initialize(page, type) ⇒ Route
constructor
Initialize with a Mechanize::Page and a specific type The page should be the detail view of m.bahn.de Parameters: * page => Mechanize::Page * type => :door2door or :station2station.
-
#start ⇒ Object
Starting point of the route.
-
#start_time ⇒ Object
Start time of the route.
-
#start_time_from_now ⇒ Object
Start time from now in words.
-
#target ⇒ Object
Target point of the route.
Constructor Details
#initialize(page, type) ⇒ Route
Initialize with a Mechanize::Page and a specific type The page should be the detail view of m.bahn.de Parameters: * page => Mechanize::Page
-
type => :door2door or :station2station
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bahn/bahn_route.rb', line 15 def initialize page, type summary_time = page.search("//div[contains(@class, 'querysummary2')]").text.gsub("\n", " ").strip html_parts = page.search("//div[contains(@class, 'haupt')]") price = html_parts.pop.text html_parts.pop @type = type route = "" html_parts.each do |part| text = part.text.strip next if text.start_with? "Reiseprofil" # not important route << text << "\n" end route = route.split("\n") create_door2door route, summary_time if @type == :door2door create_station2station route if @type == :station2station end |
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts.
8 9 10 |
# File 'lib/bahn/bahn_route.rb', line 8 def parts @parts end |
#price ⇒ Object
Returns the value of attribute price.
8 9 10 |
# File 'lib/bahn/bahn_route.rb', line 8 def price @price end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/bahn/bahn_route.rb', line 8 def type @type end |
Instance Method Details
#end_time ⇒ Object
End time of the route
49 50 51 |
# File 'lib/bahn/bahn_route.rb', line 49 def end_time @parts.last.start_time end |
#end_time_from_now ⇒ Object
End time from now in words
39 40 41 |
# File 'lib/bahn/bahn_route.rb', line 39 def end_time_from_now distance_of_time_in_words DateTime.now, @parts.last.start_time end |
#start ⇒ Object
Starting point of the route
54 55 56 |
# File 'lib/bahn/bahn_route.rb', line 54 def start @parts.first.start end |
#start_time ⇒ Object
Start time of the route
44 45 46 |
# File 'lib/bahn/bahn_route.rb', line 44 def start_time @parts.first.start_time end |
#start_time_from_now ⇒ Object
Start time from now in words
34 35 36 |
# File 'lib/bahn/bahn_route.rb', line 34 def start_time_from_now distance_of_time_in_words DateTime.now, @parts.first.start_time end |
#target ⇒ Object
Target point of the route
59 60 61 |
# File 'lib/bahn/bahn_route.rb', line 59 def target @parts.last.target end |