Class: Bahn::RoutePart

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

Overview

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

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

#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_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

#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

#to_sObject

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



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

def to_s
	"Am #{start_time.to_date} von #{start_time.to_formatted_s :time} bis #{end_time.to_date.to_s + ' ' if end_time.to_date != start_time.to_date}#{end_time.to_formatted_s :time} : #{start} nach #{target} via #{type}"
end

#transport_typeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bahn/bahn_routepart.rb', line 20

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