Class: RailFeeds::NetworkRail::Schedule::TrainSchedule::Location::Intermediate
- Inherits:
-
RailFeeds::NetworkRail::Schedule::TrainSchedule::Location
- Object
- RailFeeds::NetworkRail::Schedule::TrainSchedule::Location
- RailFeeds::NetworkRail::Schedule::TrainSchedule::Location::Intermediate
- Defined in:
- lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb
Overview
A class for holding information about a particular train’s particular location
Instance Attribute Summary collapse
-
#engineering_allowance ⇒ Float
Number of minutes.
- #line ⇒ String
- #path ⇒ String
-
#pathing_allowance ⇒ Float
Number of minutes.
-
#performance_allowance ⇒ Float
Number of minutes.
-
#public_arrival ⇒ String
The public arrival time (HHMM).
-
#public_departure ⇒ String
The public departure time (HHMM).
-
#scheduled_arrival ⇒ String
The scheduled time for arriving at the location.
-
#scheduled_departure ⇒ String
The sheduled time for departing from the location.
-
#scheduled_pass ⇒ String
The scheduled time for passing 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 rubocop:disable Metrics/MethodLength Initialize a new intermediate location from a CIF file line.
Instance Method Summary collapse
-
#initialize(**attributes) ⇒ Intermediate
constructor
A new instance of Intermediate.
-
#to_cif ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
-
#to_hash_for_json ⇒ Object
rubocop:disable Metrics/MethodLength.
Methods inherited from RailFeeds::NetworkRail::Schedule::TrainSchedule::Location
Constructor Details
#initialize(**attributes) ⇒ Intermediate
Returns a new instance of Intermediate.
37 38 39 40 41 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 37 def initialize(**attributes) attributes.each do |attribute, value| send "#{attribute}=", value end end |
Instance Attribute Details
#engineering_allowance ⇒ Float
Returns Number of minutes.
31 32 33 34 35 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 attr_accessor :line, :path, :scheduled_arrival, :scheduled_departure, :scheduled_pass, :public_arrival, :public_departure, :engineering_allowance, :pathing_allowance, :performance_allowance |
#line ⇒ String
31 32 33 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 def line @line end |
#path ⇒ String
31 32 33 34 35 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 attr_accessor :line, :path, :scheduled_arrival, :scheduled_departure, :scheduled_pass, :public_arrival, :public_departure, :engineering_allowance, :pathing_allowance, :performance_allowance |
#pathing_allowance ⇒ Float
Returns Number of minutes.
31 32 33 34 35 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 attr_accessor :line, :path, :scheduled_arrival, :scheduled_departure, :scheduled_pass, :public_arrival, :public_departure, :engineering_allowance, :pathing_allowance, :performance_allowance |
#performance_allowance ⇒ Float
Returns Number of minutes.
31 32 33 34 35 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 attr_accessor :line, :path, :scheduled_arrival, :scheduled_departure, :scheduled_pass, :public_arrival, :public_departure, :engineering_allowance, :pathing_allowance, :performance_allowance |
#public_arrival ⇒ String
Returns The public arrival time (HHMM).
31 32 33 34 35 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 attr_accessor :line, :path, :scheduled_arrival, :scheduled_departure, :scheduled_pass, :public_arrival, :public_departure, :engineering_allowance, :pathing_allowance, :performance_allowance |
#public_departure ⇒ String
Returns The public departure time (HHMM).
31 32 33 34 35 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 attr_accessor :line, :path, :scheduled_arrival, :scheduled_departure, :scheduled_pass, :public_arrival, :public_departure, :engineering_allowance, :pathing_allowance, :performance_allowance |
#scheduled_arrival ⇒ String
Returns The scheduled time for arriving at the location.
31 32 33 34 35 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 attr_accessor :line, :path, :scheduled_arrival, :scheduled_departure, :scheduled_pass, :public_arrival, :public_departure, :engineering_allowance, :pathing_allowance, :performance_allowance |
#scheduled_departure ⇒ String
Returns The sheduled time for departing from the location.
31 32 33 34 35 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 attr_accessor :line, :path, :scheduled_arrival, :scheduled_departure, :scheduled_pass, :public_arrival, :public_departure, :engineering_allowance, :pathing_allowance, :performance_allowance |
#scheduled_pass ⇒ String
Returns The scheduled time for passing the location.
31 32 33 34 35 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31 attr_accessor :line, :path, :scheduled_arrival, :scheduled_departure, :scheduled_pass, :public_arrival, :public_departure, :engineering_allowance, :pathing_allowance, :performance_allowance |
Class Method Details
.from_cif(line) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength Initialize a new intermediate location from a CIF file line
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 46 def self.from_cif(line) fail ArgumentError, "Invalid line:\n#{line}" unless line[0..1].eql?('LI') new( tiploc: line[2..8].strip, tiploc_suffix: line[9].to_i, scheduled_arrival: line[10..14].strip, scheduled_departure: line[15..19].strip, scheduled_pass: line[20..24].strip, public_arrival: line[25..28].strip, public_departure: line[29..32].strip, platform: line[33..35].strip, line: line[36..38].strip, path: line[39..41].strip, activity: line[42..53].strip, engineering_allowance: parse_allowance(line[54..55].strip), pathing_allowance: parse_allowance(line[56..57].strip), performance_allowance: parse_allowance(line[58..59].strip) ) end |
Instance Method Details
#to_cif ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 71 def to_cif format('%-80.80s', [ 'LI', format('%-7.7s', tiploc), format('%-1.1s', tiploc_suffix), format('%-5.5s', scheduled_arrival), format('%-5.5s', scheduled_departure), format('%-5.5s', scheduled_pass), format('%-4.4s', public_arrival), format('%-4.4s', public_departure), format('%-3.3s', platform), format('%-3.3s', line), format('%-3.3s', path), format('%-12.12s', activity), format('%-2.2s', allowance_cif(engineering_allowance)), format('%-2.2s', allowance_cif(pathing_allowance)), format('%-2.2s', allowance_cif(performance_allowance)) ].join) + "\n" end |
#to_hash_for_json ⇒ Object
rubocop:disable Metrics/MethodLength
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 94 def to_hash_for_json { location_type: 'LI', record_identity: 'LI', tiploc_code: tiploc, tiploc_instance: tiploc_suffix, arrival: scheduled_arrival, departure: scheduled_departure, pass: scheduled_pass, public_arrival: public_arrival, public_departure: public_departure, platform: platform, line: line, path: path, engineering_allowance: allowance_json(engineering_allowance), pathing_allowance: allowance_json(pathing_allowance), performance_allowance: allowance_json(performance_allowance) } end |