Class: TrainMovement
- Inherits:
-
Object
- Object
- TrainMovement
- Defined in:
- lib/train_movement.rb
Instance Attribute Summary collapse
-
#location_full_name ⇒ Object
(also: #station)
readonly
Returns the value of attribute location_full_name.
Instance Method Summary collapse
- #arrival ⇒ Object
- #departure ⇒ Object
-
#initialize(hash) ⇒ TrainMovement
constructor
A new instance of TrainMovement.
- #location ⇒ Object
- #train ⇒ Object
Constructor Details
#initialize(hash) ⇒ TrainMovement
Returns a new instance of TrainMovement.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/train_movement.rb', line 5 def initialize hash @train_code = hash['TrainCode'] @train_date = Time.parse hash['TrainDate'] @location_code = hash['LocationCode'] @location_full_name = hash['LocationFullName'] @location_order = hash['LocationOrder'].to_i @location_type = hash['LocationType'] @train_origin = hash['TrainOrigin'] @scheduled_arrival = Time.parse hash['ScheduledArrival'] @scheduled_departure = Time.parse hash['ScheduledDeparture'] @expected_arrival = Time.parse hash['ExpectedArrival'] @expected_departure = Time.parse hash['ExpectedDeparture'] arrival_time = hash['Arrival'] departure_time = hash['Departure'] @arrival = arrival_time.nil? ? @expected_arrival : Time.parse(arrival_time) @departure = departure_time.nil? ? @expected_departure : Time.parse(departure_time) end |
Instance Attribute Details
#location_full_name ⇒ Object (readonly) Also known as: station
Returns the value of attribute location_full_name.
3 4 5 |
# File 'lib/train_movement.rb', line 3 def location_full_name @location_full_name end |
Instance Method Details
#arrival ⇒ Object
27 28 29 |
# File 'lib/train_movement.rb', line 27 def arrival {scheduled: @scheduled_arrival, expected: @expected_arrival, actual: @arrival} end |
#departure ⇒ Object
31 32 33 |
# File 'lib/train_movement.rb', line 31 def departure {scheduled: @scheduled_departure, expected: @expected_departure, actual: @departure} end |
#location ⇒ Object
23 24 25 |
# File 'lib/train_movement.rb', line 23 def location {code: @location_code, name: @location_full_name, stop_number: @location_order, type: @location_type} end |
#train ⇒ Object
35 36 37 |
# File 'lib/train_movement.rb', line 35 def train {code: @train_code, date: @train_date, origin: @train_origin} end |