Class: Train
- Inherits:
-
Object
- Object
- Train
- Defined in:
- lib/viaggiatreno/train.rb
Instance Attribute Summary collapse
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#last_update ⇒ Object
Returns the value of attribute last_update.
-
#state ⇒ Object
Returns the value of attribute state.
-
#status ⇒ Object
Returns the value of attribute status.
-
#train_name ⇒ Object
Returns the value of attribute train_name.
-
#train_number ⇒ Object
Returns the value of attribute train_number.
Instance Method Summary collapse
- #actual_arriving_time ⇒ Object
- #actual_departing_time ⇒ Object
- #actual_stop_time(station_name) ⇒ Object
- #add_stop(train_stop) ⇒ Object
- #arriving_station ⇒ Object
- #departing_station ⇒ Object
-
#initialize(train_number) ⇒ Train
constructor
A new instance of Train.
- #last_stop ⇒ Object
- #scheduled_arriving_time ⇒ Object
- #scheduled_departing_time ⇒ Object
- #scheduled_stop_time(station_name) ⇒ Object
- #to_s ⇒ Object
- #train_stops ⇒ Object
- #update ⇒ Object
- #update_details ⇒ Object
Constructor Details
#initialize(train_number) ⇒ Train
Returns a new instance of Train.
8 9 10 11 12 |
# File 'lib/viaggiatreno/train.rb', line 8 def initialize(train_number) @train_number = train_number @scraper = Scraper.new(train_number.to_s, self) update end |
Instance Attribute Details
#delay ⇒ Object
Returns the value of attribute delay.
6 7 8 |
# File 'lib/viaggiatreno/train.rb', line 6 def delay @delay end |
#last_update ⇒ Object
Returns the value of attribute last_update.
6 7 8 |
# File 'lib/viaggiatreno/train.rb', line 6 def last_update @last_update end |
#state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'lib/viaggiatreno/train.rb', line 6 def state @state end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/viaggiatreno/train.rb', line 6 def status @status end |
#train_name ⇒ Object
Returns the value of attribute train_name.
6 7 8 |
# File 'lib/viaggiatreno/train.rb', line 6 def train_name @train_name end |
#train_number ⇒ Object
Returns the value of attribute train_number.
6 7 8 |
# File 'lib/viaggiatreno/train.rb', line 6 def train_number @train_number end |
Instance Method Details
#actual_arriving_time ⇒ Object
57 58 59 |
# File 'lib/viaggiatreno/train.rb', line 57 def actual_arriving_time train_stops.last.actual_stop_time.to_s end |
#actual_departing_time ⇒ Object
53 54 55 |
# File 'lib/viaggiatreno/train.rb', line 53 def actual_departing_time train_stops.first.actual_stop_time.to_s end |
#actual_stop_time(station_name) ⇒ Object
65 66 67 |
# File 'lib/viaggiatreno/train.rb', line 65 def actual_stop_time(station_name) find_stop_time(station_name)['actual'] end |
#add_stop(train_stop) ⇒ Object
28 29 30 |
# File 'lib/viaggiatreno/train.rb', line 28 def add_stop(train_stop) @train_stops << train_stop end |
#arriving_station ⇒ Object
41 42 43 |
# File 'lib/viaggiatreno/train.rb', line 41 def arriving_station train_stops.last.train_station.to_s end |
#departing_station ⇒ Object
37 38 39 |
# File 'lib/viaggiatreno/train.rb', line 37 def departing_station train_stops.first.train_station.to_s end |
#last_stop ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/viaggiatreno/train.rb', line 69 def last_stop return train_stops.last.to_s if @state == TrainState::ARRIVED train_stops.each_with_index do |train_stop, index| if train_stop.status == TrainStopState::DONE && \ train_stops[index + 1].status == TrainStopState::TO_BE_DONE return train_stop.to_s end end nil end |
#scheduled_arriving_time ⇒ Object
49 50 51 |
# File 'lib/viaggiatreno/train.rb', line 49 def scheduled_arriving_time train_stops.last.scheduled_stop_time.to_s end |
#scheduled_departing_time ⇒ Object
45 46 47 |
# File 'lib/viaggiatreno/train.rb', line 45 def scheduled_departing_time train_stops.first.scheduled_stop_time.to_s end |
#scheduled_stop_time(station_name) ⇒ Object
61 62 63 |
# File 'lib/viaggiatreno/train.rb', line 61 def scheduled_stop_time(station_name) find_stop_time(station_name)['scheduled'] end |
#to_s ⇒ Object
23 24 25 26 |
# File 'lib/viaggiatreno/train.rb', line 23 def to_s "#{@train_number} #{@train_name}: #{@status} state: #{@state}, \ delay: #{@delay}, last_update: #{@last_update}" end |
#train_stops ⇒ Object
32 33 34 35 |
# File 'lib/viaggiatreno/train.rb', line 32 def train_stops update_details if @train_stops.nil? @train_stops end |
#update ⇒ Object
14 15 16 |
# File 'lib/viaggiatreno/train.rb', line 14 def update @scraper.update_train end |
#update_details ⇒ Object
18 19 20 21 |
# File 'lib/viaggiatreno/train.rb', line 18 def update_details @train_stops = [] @scraper.update_train_details end |