Class: Bahn::RoutePart

Inherits:
Object
  • Object
show all
Defined in:
lib/bahn/bahn_routepart.rb

Overview

Route Parts show a small step of the route from A to B with one specific type of transportation Example: “Am 2013-02-01 von 17:33 bis 17:47 : Heerdter Sandberg U, Düsseldorf nach Düsseldorf Hauptbahnhof via U 7”

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoutePart

Returns a new instance of RoutePart.



9
10
11
12
# File 'lib/bahn/bahn_routepart.rb', line 9

def initialize
  @start_delay = 0
  @target_delay = 0
end

Instance Attribute Details

#end_timeObject

Returns the value of attribute end_time.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def end_time
  @end_time
end

#platform_startObject

Returns the value of attribute platform_start.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def platform_start
  @platform_start
end

#platform_targetObject

Returns the value of attribute platform_target.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def platform_target
  @platform_target
end

#priceObject

Returns the value of attribute price.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def price
  @price
end

#startObject

Returns the value of attribute start.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def start
  @start
end

#start_delayObject

Returns the value of attribute start_delay.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def start_delay
  @start_delay
end

#start_timeObject

Returns the value of attribute start_time.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def start_time
  @start_time
end

#targetObject

Returns the value of attribute target.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def target
  @target
end

#target_delayObject

Returns the value of attribute target_delay.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def target_delay
  @target_delay
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/bahn/bahn_routepart.rb', line 7

def type
  @type
end

Instance Method Details

#==(rp) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/bahn/bahn_routepart.rb', line 45

def ==(rp)
  self.start == rp.start &&
    self.target == rp.target &&
    self.type == rp.type &&
    self.platform_start == rp.platform_start &&
    self.platform_target == rp.platform_target && 
    self.start_time == rp.start_time &&
    self.end_time == rp.end_time
end

#to_sObject

Return a nicely formatted route Raises errors if not everything is set properly



16
17
18
19
20
21
22
23
24
# File 'lib/bahn/bahn_routepart.rb', line 16

def to_s
  "Am %s von %s%s bis %s%s: %s (Gl. %s) nach %s (Gl. %s) via %s" % 
    [ start_time.to_date,
      start_time.to_formatted_s(:time),
      (start_delay > 0 ? " (+%i)" % start_delay : ""),
      (end_time.to_date != start_time.to_date ? end_time.to_date.to_s + ' ' : "") + end_time.to_formatted_s(:time),
      target_delay > 0 ? " (+%i)" % target_delay : "",
      start.name, platform_start, target.name, platform_target, type]
end

#transport_typeObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bahn/bahn_routepart.rb', line 31

def transport_type
  short_type = self.type.split.first.downcase
  if ["str", "u", "s", "re", "erb", "ic", "ice"].include? short_type
    return :train
  elsif ["bus", "ne"].include? short_type
    return :bus
  elsif "Fußweg" == short_type
    return :foot
  end
  
  # nothing else works
  self.type
end