Class: RailFeeds::NetworkRail::Schedule::TrainSchedule::Location::Intermediate

Inherits:
RailFeeds::NetworkRail::Schedule::TrainSchedule::Location show all
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

Attributes inherited from RailFeeds::NetworkRail::Schedule::TrainSchedule::Location

#activity, #platform, #tiploc, #tiploc_suffix

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RailFeeds::NetworkRail::Schedule::TrainSchedule::Location

#==, #hash

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_allowanceFloat

Returns Number of minutes.

Returns:

  • (Float)

    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

#lineString

Returns:

  • (String)


31
32
33
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/intermediate.rb', line 31

def line
  @line
end

#pathString

Returns:

  • (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_allowanceFloat

Returns Number of minutes.

Returns:

  • (Float)

    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_allowanceFloat

Returns Number of minutes.

Returns:

  • (Float)

    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_arrivalString

Returns The public arrival time (HHMM).

Returns:

  • (String)

    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_departureString

Returns The public departure time (HHMM).

Returns:

  • (String)

    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_arrivalString

Returns The scheduled time for arriving at the location.

Returns:

  • (String)

    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_departureString

Returns The sheduled time for departing from the location.

Returns:

  • (String)

    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_passString

Returns The scheduled time for passing the location.

Returns:

  • (String)

    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_cifObject

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_jsonObject

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