class RailFeeds::NetworkRail::Schedule::Tiploc

A class for holding information about a particular tiploc record

Attributes

crs[RW]

@!attribute [rw] tiploc

@return [String] The timing point location code.

@!attribute [rw] nlc

@return [String] The national location code.

@!attribute [rw] nlc_description

@return [String] Description of location used in CAPRI.

@!attribute [rw] tps_description

@return [String] Description of location.

@!attribute [rw] stanox

@return [Integer] The TOPS location code.

@!attribute [rw] crs

@return [String] The CRS / 3 Alpha code for the location.
nlc[RW]

@!attribute [rw] tiploc

@return [String] The timing point location code.

@!attribute [rw] nlc

@return [String] The national location code.

@!attribute [rw] nlc_description

@return [String] Description of location used in CAPRI.

@!attribute [rw] tps_description

@return [String] Description of location.

@!attribute [rw] stanox

@return [Integer] The TOPS location code.

@!attribute [rw] crs

@return [String] The CRS / 3 Alpha code for the location.
nlc_description[RW]

@!attribute [rw] tiploc

@return [String] The timing point location code.

@!attribute [rw] nlc

@return [String] The national location code.

@!attribute [rw] nlc_description

@return [String] Description of location used in CAPRI.

@!attribute [rw] tps_description

@return [String] Description of location.

@!attribute [rw] stanox

@return [Integer] The TOPS location code.

@!attribute [rw] crs

@return [String] The CRS / 3 Alpha code for the location.
stanox[RW]

@!attribute [rw] tiploc

@return [String] The timing point location code.

@!attribute [rw] nlc

@return [String] The national location code.

@!attribute [rw] nlc_description

@return [String] Description of location used in CAPRI.

@!attribute [rw] tps_description

@return [String] Description of location.

@!attribute [rw] stanox

@return [Integer] The TOPS location code.

@!attribute [rw] crs

@return [String] The CRS / 3 Alpha code for the location.
tiploc[RW]

@!attribute [rw] tiploc

@return [String] The timing point location code.

@!attribute [rw] nlc

@return [String] The national location code.

@!attribute [rw] nlc_description

@return [String] Description of location used in CAPRI.

@!attribute [rw] tps_description

@return [String] Description of location.

@!attribute [rw] stanox

@return [Integer] The TOPS location code.

@!attribute [rw] crs

@return [String] The CRS / 3 Alpha code for the location.
tps_description[RW]

@!attribute [rw] tiploc

@return [String] The timing point location code.

@!attribute [rw] nlc

@return [String] The national location code.

@!attribute [rw] nlc_description

@return [String] Description of location used in CAPRI.

@!attribute [rw] tps_description

@return [String] Description of location.

@!attribute [rw] stanox

@return [Integer] The TOPS location code.

@!attribute [rw] crs

@return [String] The CRS / 3 Alpha code for the location.

Public Class Methods

from_cif(line) click to toggle source

Initialize a new tiploc from a CIF file line

# File lib/rail_feeds/network_rail/schedule/tiploc.rb, line 32
def self.from_cif(line)
  unless %w[TI TA TD].include?(line[0..1])
    fail ArgumentError, "Invalid line:\n#{line}"
  end

  new(
    tiploc: line[2..8].strip,
    nlc: Schedule.nil_or_i(line[11..16]),
    nlc_description: line[56..71].strip,
    tps_description: line[18..43].strip,
    stanox: Schedule.nil_or_i(line[44..48]),
    crs: line[53..55].strip
  )
end
from_json(line) click to toggle source

Initialize a new tiploc from a JSON file line

# File lib/rail_feeds/network_rail/schedule/tiploc.rb, line 48
def self.from_json(line)
  data = ::JSON.parse(line)['TiplocV1']

  new(
    tiploc: data['tiploc_code'],
    nlc: Schedule.nil_or_i(data['nalco']),
    stanox: Schedule.nil_or_i(data['stanox']),
    crs: data['crs_code'],
    nlc_description: Schedule.nil_or_strip(data['description']),
    tps_description: data['tps_description']
  )
end
new(**attributes) click to toggle source
# File lib/rail_feeds/network_rail/schedule/tiploc.rb, line 25
def initialize(**attributes)
  attributes.each do |attribute, value|
    send "#{attribute}=", value
  end
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/rail_feeds/network_rail/schedule/tiploc.rb, line 61
def <=>(other)
  hash <=> other&.hash
end
hash() click to toggle source
# File lib/rail_feeds/network_rail/schedule/tiploc.rb, line 65
def hash
  tiploc.dup
end
to_cif() click to toggle source

rubocop:disable Style/FormatStringToken

# File lib/rail_feeds/network_rail/schedule/tiploc.rb, line 70
def to_cif
  format('%-80.80s', [
    'TI',
    format('%-7.7s', tiploc),
    '  ',
    format('%-6.6s', nlc),
    ' ',
    format('%-26.26s', tps_description),
    format('%-5.5s', stanox),
    '    ',
    format('%-3.3s', crs),
    format('%-16.16s', nlc_description)
  ].join) + "\n"
end
to_json(**opts) click to toggle source

rubocop:enable Style/FormatStringToken

# File lib/rail_feeds/network_rail/schedule/tiploc.rb, line 86
def to_json(**opts)
  {
    'TiplocV1' => {
      'transaction_type' => 'Create',
      'tiploc_code' => tiploc,
      'nalco' => nlc.to_s,
      'stanox' => stanox.to_s,
      'crs_code' => crs,
      'description' => nlc_description,
      'tps_description' => tps_description
    }
  }.to_json(**opts)
end