Class: RailFeeds::NetworkRail::Schedule::TrainSchedule::ChangeEnRoute
- Inherits:
-
Object
- Object
- RailFeeds::NetworkRail::Schedule::TrainSchedule::ChangeEnRoute
- Defined in:
- lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb
Overview
A class for holding information about a particular train’s change en route
Instance Attribute Summary collapse
-
#branding ⇒ String?
The train’s new branding.
-
#category ⇒ String
The train’s new category.
-
#catering ⇒ String?
The train’s new catering.
-
#operating_characteristics ⇒ String?
The train’s new operating_characteristics.
-
#portion_id ⇒ String?
The train’s new portion_id.
-
#power_type ⇒ String
The train’s new power_type.
-
#reservation_headcode ⇒ Integer?
The train’s new reservation_headcode.
-
#reservations ⇒ String?
The train’s new reservations.
-
#seating_class ⇒ String?
The train’s new seating_class.
-
#service_code ⇒ String
The train’s new service_code.
-
#signalling_headcode ⇒ String?
The train’s new signalling_headcode.
-
#sleeping_class ⇒ String?
The train’s new sleeping_class.
-
#speed ⇒ Integer
The train’s new speed.
-
#timing_load ⇒ String?
The train’s new timing_load.
-
#tiploc ⇒ String
The location where the change occurs.
- #tiploc_suffix ⇒ String
-
#uic_code ⇒ Integer?
The train’s new uic_code.
Class Method Summary collapse
-
.from_cif(line) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength Initialize a new change en route from a CIF file line.
Instance Method Summary collapse
-
#==(other) ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength.
-
#apply_to(train) ⇒ RailFeeds::NetworkRail::Schedule::TrainSchedule
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength Apply these changes to a train.
-
#hash ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength rubocop:enable Style/FormatStringToken.
-
#initialize(**attributes) ⇒ ChangeEnRoute
constructor
A new instance of ChangeEnRoute.
-
#to_cif ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Style/FormatStringToken.
- #to_hash_for_json ⇒ Object
Constructor Details
#initialize(**attributes) ⇒ ChangeEnRoute
Returns a new instance of ChangeEnRoute.
50 51 52 53 54 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 50 def initialize(**attributes) attributes.each do |attribute, value| send "#{attribute}=", value end end |
Instance Attribute Details
#branding ⇒ String?
Returns The train’s new branding.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#category ⇒ String
Returns The train’s new category.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#catering ⇒ String?
Returns The train’s new catering.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#operating_characteristics ⇒ String?
Returns The train’s new operating_characteristics.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#portion_id ⇒ String?
Returns The train’s new portion_id.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#power_type ⇒ String
Returns The train’s new power_type.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#reservation_headcode ⇒ Integer?
Returns The train’s new reservation_headcode.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#reservations ⇒ String?
Returns The train’s new reservations.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#seating_class ⇒ String?
Returns The train’s new seating_class.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#service_code ⇒ String
Returns The train’s new service_code.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#signalling_headcode ⇒ String?
Returns The train’s new signalling_headcode.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#sleeping_class ⇒ String?
Returns The train’s new sleeping_class.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#speed ⇒ Integer
Returns The train’s new speed.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#timing_load ⇒ String?
Returns The train’s new timing_load.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#tiploc ⇒ String
Returns The location where the change occurs.
44 45 46 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 def tiploc @tiploc end |
#tiploc_suffix ⇒ String
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
#uic_code ⇒ Integer?
Returns The train’s new uic_code.
44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 44 attr_accessor :tiploc, :tiploc_suffix, :category, :signalling_headcode, :reservation_headcode, :service_code, :portion_id, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic_code |
Class Method Details
.from_cif(line) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength Initialize a new change en route from a CIF file line
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 59 def self.from_cif(line) fail ArgumentError, "Invalid line:\n#{line}" unless line[0..1].eql?('CR') new( tiploc: line[2..8].strip, tiploc_suffix: line[9].to_i, category: line[10..11].strip, signalling_headcode: line[12..15].strip, reservation_headcode: Schedule.nil_or_i(line[16..19]), service_code: Schedule.nil_or_i(line[21..28]), portion_id: Schedule.nil_or_strip(line[29]), power_type: line[30..32].strip, timing_load: Schedule.nil_or_strip(line[33..36]), speed: Schedule.nil_or_i(line[37..39]), operating_characteristics: line[40..45].strip, seating_class: Schedule.nil_or_strip(line[46]), sleeping_class: Schedule.nil_or_strip(line[47]), reservations: Schedule.nil_or_strip(line[48]), catering: line[50..53].strip, branding: Schedule.nil_or_strip(line[54..57]), uic_code: Schedule.nil_or_strip(line[62..66]) ) end |
Instance Method Details
#==(other) ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength
113 114 115 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 113 def ==(other) hash == other&.hash end |
#apply_to(train) ⇒ RailFeeds::NetworkRail::Schedule::TrainSchedule
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength Apply these changes to a train.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 92 def apply_to(train) train.category = category train.signalling_headcode = signalling_headcode train.reservation_headcode = reservation_headcode train.service_code = service_code train.portion_id = portion_id train.power_type = power_type train.timing_load = timing_load train.speed = speed train. = train.seating_class = seating_class train.sleeping_class = sleeping_class train.reservations = reservations train.catering = catering train.branding = branding train.uic_code = uic_code train end |
#hash ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength rubocop:enable Style/FormatStringToken
149 150 151 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 149 def hash "#{tiploc}-#{tiploc_suffix}" end |
#to_cif ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Style/FormatStringToken
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 120 def to_cif format('%-80.80s', [ 'CR', format('%-7.7s', tiploc), format('%-1.1s', tiploc_suffix), format('%-2.2s', category), format('%-4.4s', signalling_headcode), format('%-4.4s', reservation_headcode), ' ', format('%-8.8s', service_code), format('%-1.1s', portion_id), format('%-3.3s', power_type), format('%-4.4s', timing_load), format('%-3.3s', speed), format('%-6.6s', ), format('%-1.1s', seating_class), format('%-1.1s', sleeping_class), format('%-1.1s', reservations), ' ', format('%-4.4s', catering), format('%-4.4s', branding), ' ', format('%-5.5s', uic_code) ].join) + "\n" end |
#to_hash_for_json ⇒ Object
153 154 155 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb', line 153 def to_hash_for_json nil end |