Class: RailFeeds::NetworkRail::Schedule::TrainSchedule::Location::Terminating
- Inherits:
-
RailFeeds::NetworkRail::Schedule::TrainSchedule::Location
- Object
- RailFeeds::NetworkRail::Schedule::TrainSchedule::Location
- RailFeeds::NetworkRail::Schedule::TrainSchedule::Location::Terminating
- Defined in:
- lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb
Overview
A class for holding info about a particular train’s terminating location
Instance Attribute Summary collapse
- #path ⇒ String
-
#public_arrival ⇒ String
The public arrival time (HHMM).
-
#scheduled_arrival ⇒ String
The scheduled time for arriving at the location.
Attributes inherited from RailFeeds::NetworkRail::Schedule::TrainSchedule::Location
#activity, #platform, #tiploc, #tiploc_suffix
Class Method Summary collapse
-
.from_cif(line) ⇒ Object
rubocop:disable Metrics/AbcSize Initialize a new terminating from a CIF file line.
Instance Method Summary collapse
-
#initialize(**attributes) ⇒ Terminating
constructor
A new instance of Terminating.
-
#to_cif ⇒ Object
rubocop:enable Metrics/AbcSize.
- #to_hash_for_json ⇒ Object
Methods inherited from RailFeeds::NetworkRail::Schedule::TrainSchedule::Location
Constructor Details
#initialize(**attributes) ⇒ Terminating
Returns a new instance of Terminating.
19 20 21 22 23 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 19 def initialize(**attributes) attributes.each do |attribute, value| send "#{attribute}=", value end end |
Instance Attribute Details
#path ⇒ String
17 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 17 attr_accessor :scheduled_arrival, :public_arrival, :path |
#public_arrival ⇒ String
Returns The public arrival time (HHMM).
17 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 17 attr_accessor :scheduled_arrival, :public_arrival, :path |
#scheduled_arrival ⇒ String
Returns The scheduled time for arriving at the location.
17 18 19 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 17 def scheduled_arrival @scheduled_arrival end |
Class Method Details
.from_cif(line) ⇒ Object
rubocop:disable Metrics/AbcSize Initialize a new terminating from a CIF file line
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 27 def self.from_cif(line) fail ArgumentError, "Invalid line:\n#{line}" unless line[0..1].eql?('LT') new( tiploc: line[2..8].strip, tiploc_suffix: line[9].to_i, scheduled_arrival: line[10..14].strip, public_arrival: line[15..18].strip, platform: line[19..21].strip, path: line[22..24].strip, activity: line[25..36].strip ) end |
Instance Method Details
#to_cif ⇒ Object
rubocop:enable Metrics/AbcSize
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 42 def to_cif format('%-80.80s', [ 'LT', format('%-7.7s', tiploc), format('%-1.1s', tiploc_suffix), format('%-5.5s', scheduled_arrival), format('%-4.4s', public_arrival), format('%-3.3s', platform), format('%-3.3s', path), format('%-12.12s', activity) ].join) + "\n" end |
#to_hash_for_json ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 55 def to_hash_for_json { location_type: 'LT', record_identity: 'LT', tiploc_code: tiploc, tiploc_instance: tiploc_suffix, arrival: scheduled_arrival, public_arrival: public_arrival, platform: platform, path: path } end |