Class: RailFeeds::NetworkRail::Schedule::TrainSchedule::ChangeEnRoute

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#brandingString?

Returns The train’s new branding.

Returns:

  • (String, nil)

    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

#categoryString

Returns The train’s new category.

Returns:

  • (String)

    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

#cateringString?

Returns The train’s new catering.

Returns:

  • (String, nil)

    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_characteristicsString?

Returns The train’s new operating_characteristics.

Returns:

  • (String, nil)

    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_idString?

Returns The train’s new portion_id.

Returns:

  • (String, nil)

    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_typeString

Returns The train’s new power_type.

Returns:

  • (String)

    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_headcodeInteger?

Returns The train’s new reservation_headcode.

Returns:

  • (Integer, nil)

    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

#reservationsString?

Returns The train’s new reservations.

Returns:

  • (String, nil)

    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_classString?

Returns The train’s new seating_class.

Returns:

  • (String, nil)

    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_codeString

Returns The train’s new service_code.

Returns:

  • (String)

    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_headcodeString?

Returns The train’s new signalling_headcode.

Returns:

  • (String, nil)

    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_classString?

Returns The train’s new sleeping_class.

Returns:

  • (String, nil)

    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

#speedInteger

Returns The train’s new speed.

Returns:

  • (Integer)

    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_loadString?

Returns The train’s new timing_load.

Returns:

  • (String, nil)

    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

#tiplocString

Returns The location where the change occurs.

Returns:

  • (String)

    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_suffixString

Returns:

  • (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_codeInteger?

Returns The train’s new uic_code.

Returns:

  • (Integer, nil)

    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.

Parameters:

Returns:



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.operating_characteristics = operating_characteristics
  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

#hashObject

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_cifObject

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', operating_characteristics),
    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_jsonObject



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