Class: RailFeeds::NetworkRail::Schedule::TrainSchedule
- Inherits:
-
Object
- Object
- RailFeeds::NetworkRail::Schedule::TrainSchedule
- Includes:
- Comparable, Days, STPIndicator
- Defined in:
- lib/rail_feeds/network_rail/schedule/train_schedule.rb,
lib/rail_feeds/network_rail/schedule/train_schedule/location.rb,
lib/rail_feeds/network_rail/schedule/train_schedule/change_en_route.rb,
lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb,
lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb,
lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb
Overview
rubocop:disable Metrics/ClassLength A class for holding information about a particular train
Defined Under Namespace
Classes: ChangeEnRoute, Location
Instance Attribute Summary collapse
-
#applicable_timetable ⇒ Boolean?
performance monitoring (Applicable Timetable Service).
- #atoc ⇒ Object
-
#bank_holiday_running ⇒ String?
-
X - does not run on specified bank holiday Mondays.
-
-
#branding ⇒ String?
-
E - Eurostar.
-
- #category ⇒ String
-
#catering ⇒ String?
-
H - Hot food available * C - Buffet service * R - Restaurant * F - Restaurant for first class passengers * M - Meal included for first class passengers * T - Trolly service.
-
-
#days ⇒ Array<Boolean>
[Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday].
-
#end_date ⇒ Date
When the schedule ends.
-
#journey ⇒ Array<Location, ChangeEnRoute>
change will precede location.
- #operating_characteristics ⇒ String?
- #power_type ⇒ String
-
#reservation_headcode ⇒ Integer?
(National Reservation System).
-
#reservations ⇒ String?
-
A - Reservations Compulsory * E - Reservations for bicycles essential * R - Reservations recommended * S - Reservations possible from any station * W - Wheelchair only reservations.
-
-
#seating_class ⇒ String?
-
B or blank - First and Standard * S - Standard only.
-
-
#service_code ⇒ Integer
Used for attribution of revenue.
-
#signalling_headcode ⇒ String?
Will be nil for annonymous freight services.
-
#sleeping_class ⇒ String?
-
B - First and Standard * F - First only * S - Standard only.
-
-
#speed ⇒ Integer
The planned speed (miles per hour).
-
#start_date ⇒ Date
When the schedule starts.
- #status ⇒ String
-
#stp_indicator ⇒ String
-
C - cancellation of permanent schedule * N - new STP schedule * O - STP overlay of permanent schedule * P - permanent.
-
- #timing_load ⇒ String?
-
#uic ⇒ Integer?
For train services running to/from continental Europe.
-
#uid ⇒ String
Along with start_date uniquely identifies a schedule.
Class Method Summary collapse
-
.from_json(json) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/LineLength rubocop:disable Metrics/MethodLength Create a new train schedule from json data.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#hash ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength.
-
#initialize(**attributes) ⇒ TrainSchedule
constructor
Initialize a new train.
-
#to_cif ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/LineLength rubocop:enable Metrics/MethodLength.
-
#to_json(**opts) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
-
#update_from_cif(line) ⇒ Object
Add details from a CIF schedule file line to this train schedule.
Methods included from STPIndicator
Methods included from Days
#fridays?, included, #mondays?, #saturdays?, #sundays?, #thursdays?, #tuesdays?, #wednesdays?
Constructor Details
#initialize(**attributes) ⇒ TrainSchedule
Initialize a new train
99 100 101 102 103 104 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 99 def initialize(**attributes) @journey = [] attributes.each do |attribute, value| send "#{attribute}=", value end end |
Instance Attribute Details
#applicable_timetable ⇒ Boolean?
performance monitoring (Applicable Timetable Service).
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#atoc ⇒ Object
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#bank_holiday_running ⇒ String?
-
X - does not run on specified bank holiday Mondays.
-
G - does not run on Glasgow bank holidays.
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#branding ⇒ String?
-
E - Eurostar
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#category ⇒ String
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#catering ⇒ String?
-
H - Hot food available
-
C - Buffet service
-
R - Restaurant
-
F - Restaurant for first class passengers
-
M - Meal included for first class passengers
-
T - Trolly service
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#days ⇒ Array<Boolean>
- Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#end_date ⇒ Date
Returns When the schedule ends.
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#journey ⇒ Array<Location, ChangeEnRoute>
change will precede location.
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#operating_characteristics ⇒ String?
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#power_type ⇒ String
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#reservation_headcode ⇒ Integer?
(National Reservation System).
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#reservations ⇒ String?
-
A - Reservations Compulsory
-
E - Reservations for bicycles essential
-
R - Reservations recommended
-
S - Reservations possible from any station
-
W - Wheelchair only reservations
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#seating_class ⇒ String?
-
B or blank - First and Standard
-
S - Standard only
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#service_code ⇒ Integer
Returns Used for attribution of revenue.
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#signalling_headcode ⇒ String?
Will be nil for annonymous freight services.
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#sleeping_class ⇒ String?
-
B - First and Standard
-
F - First only
-
S - Standard only
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#speed ⇒ Integer
Returns The planned speed (miles per hour).
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#start_date ⇒ Date
Returns When the schedule starts.
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#status ⇒ String
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#stp_indicator ⇒ String
-
C - cancellation of permanent schedule
-
N - new STP schedule
-
O - STP overlay of permanent schedule
-
P - permanent
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#timing_load ⇒ String?
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#uic ⇒ Integer?
Returns For train services running to/from continental Europe.
90 91 92 93 94 95 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 attr_accessor :uid, :category, :status, :reservation_headcode, :signalling_headcode, :service_code, :start_date, :end_date, :bank_holiday_running, :power_type, :timing_load, :speed, :operating_characteristics, :seating_class, :sleeping_class, :reservations, :catering, :branding, :uic, :atoc, :applicable_timetable, :journey |
#uid ⇒ String
Along with start_date uniquely identifies a schedule.
90 91 92 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 90 def uid @uid end |
Class Method Details
.from_json(json) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/LineLength rubocop:disable Metrics/MethodLength Create a new train schedule from json data.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 130 def self.from_json(json) data = ::JSON.parse(json)['JsonScheduleV1'] locations = data.dig('schedule_segment', 'schedule_location')&.map do |location| location_from_json location end new( uid: data['CIF_train_uid'], category: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_train_category')), status: Schedule.nil_or_strip(data['train_status']), reservation_headcode: Schedule.nil_or_i(data.dig('schedule_segment', 'CIF_headcode')), signalling_headcode: Schedule.nil_or_strip(data.dig('schedule_segment', 'signalling_id')), service_code: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_train_service_code')), start_date: Date.parse(data['schedule_start_date']), end_date: data['schedule_end_date'] ? Date.parse(data['schedule_end_date']) : nil, days: days_from_cif(data['schedule_days_runs']), bank_holiday_running: Schedule.nil_or_strip(data['CIF_bank_holiday_running']), power_type: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_power_type')), timing_load: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_timing_load')), speed: Schedule.nil_or_i(data.dig('schedule_segment', 'CIF_speed')), operating_characteristics: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_operating_characteristics')), seating_class: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_train_class')), sleeping_class: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_sleepers')), reservations: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_reservations')), catering: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_catering_code')), branding: Schedule.nil_or_strip(data.dig('schedule_segment', 'CIF_service_branding')), uic: Schedule.nil_or_i(data.dig('new_schedule_segment', 'uic_code')), atoc: data['atoc_code'], applicable_timetable: data['applicable_timetable'].eql?('Y'), stp_indicator: stp_indicator_from_cif(data['CIF_stp_indicator']), journey: locations ) end |
Instance Method Details
#<=>(other) ⇒ Object
228 229 230 231 232 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 228 def <=>(other) values = [start_date, uid] other_values = [other&.start_date, other&.uid] values <=> other_values end |
#==(other) ⇒ Object
224 225 226 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 224 def ==(other) hash == other&.hash end |
#hash ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength
220 221 222 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 220 def hash "#{uid}-#{start_date&.strftime('%Y%m%d')}" end |
#to_cif ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/LineLength rubocop:enable Metrics/MethodLength
168 169 170 171 172 173 174 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 168 def to_cif [ basic_to_cif, extra_to_cif, *journey.map(&:to_cif) ].join end |
#to_json(**opts) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 178 def to_json(**opts) { 'JsonScheduleV1' => { 'CIF_bank_holiday_running' => bank_holiday_running, 'CIF_stp_indicator' => stp_indicator_to_cif, 'CIF_train_uid' => uid, 'applicable_timetable' => ( ? 'Y' : 'N'), 'atoc_code' => atoc, 'schedule_start_date' => start_date.strftime('%Y-%m-%d'), 'train_status' => status, 'transaction_type' => 'Create', 'schedule_days_runs' => days_to_cif, 'schedule_end_date' => end_date.strftime('%Y-%m-%d'), 'new_schedule_segment' => { 'traction_class' => '', 'uic_code' => uic.to_s }, 'schedule_segment' => { 'signalling_id' => signalling_headcode, 'CIF_train_category' => category, 'CIF_headcode' => reservation_headcode.to_s, 'CIF_course_indicator' => nil, 'CIF_train_service_code' => service_code, 'CIF_business_sector' => '??', 'CIF_power_type' => power_type, 'CIF_timing_load' => timing_load, 'CIF_speed' => speed.to_s.rjust(3, '0'), 'CIF_operating_characteristics' => , 'CIF_train_class' => seating_class, 'CIF_sleepers' => sleeping_class, 'CIF_reservations' => reservations, 'CIF_connection_indicator' => nil, 'CIF_catering_code' => catering, 'CIF_service_branding' => branding, 'schedule_location' => journey.map(&:to_hash_for_json).reject(&:nil?) } } }.to_json(**opts) end |
#update_from_cif(line) ⇒ Object
Add details from a CIF schedule file line to this train schedule
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/rail_feeds/network_rail/schedule/train_schedule.rb', line 107 def update_from_cif(line) type = line[0..1] if type.eql?('BS') update_basic_information line elsif type.eql?('BX') update_extra_information line elsif %w[LO LI LT].include?(type) journey.push Location.from_cif(line) elsif type.eql?('CR') journey.push ChangeEnRoute.from_cif(line) else fail ArgumentError, "Improper line type #{line[0..1]}: #{line}" end end |