Class: RailFeeds::NetworkRail::Schedule::Tiploc
- Inherits:
-
Object
- Object
- RailFeeds::NetworkRail::Schedule::Tiploc
- Includes:
- Comparable
- Defined in:
- lib/rail_feeds/network_rail/schedule/tiploc.rb
Overview
A class for holding information about a particular tiploc record
Instance Attribute Summary collapse
-
#crs ⇒ String
The CRS / 3 Alpha code for the location.
-
#nlc ⇒ String
The national location code.
-
#nlc_description ⇒ String
Description of location used in CAPRI.
-
#stanox ⇒ Integer
The TOPS location code.
-
#tiploc ⇒ String
The timing point location code.
-
#tps_description ⇒ String
Description of location.
Class Method Summary collapse
-
.from_cif(line) ⇒ Object
Initialize a new tiploc from a CIF file line.
-
.from_json(line) ⇒ Object
Initialize a new tiploc from a JSON file line.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(**attributes) ⇒ Tiploc
constructor
A new instance of Tiploc.
- #to_cif ⇒ Object
- #to_json(**opts) ⇒ Object
Constructor Details
#initialize(**attributes) ⇒ Tiploc
Returns a new instance of Tiploc.
25 26 27 28 29 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 25 def initialize(**attributes) attributes.each do |attribute, value| send "#{attribute}=", value end end |
Instance Attribute Details
#crs ⇒ String
Returns The CRS / 3 Alpha code for the location.
23 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 23 attr_accessor :tiploc, :nlc, :nlc_description, :tps_description, :stanox, :crs |
#nlc ⇒ String
Returns The national location code.
23 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 23 attr_accessor :tiploc, :nlc, :nlc_description, :tps_description, :stanox, :crs |
#nlc_description ⇒ String
Returns Description of location used in CAPRI.
23 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 23 attr_accessor :tiploc, :nlc, :nlc_description, :tps_description, :stanox, :crs |
#stanox ⇒ Integer
Returns The TOPS location code.
23 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 23 attr_accessor :tiploc, :nlc, :nlc_description, :tps_description, :stanox, :crs |
#tiploc ⇒ String
Returns The timing point location code.
23 24 25 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 23 def tiploc @tiploc end |
#tps_description ⇒ String
Returns Description of location.
23 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 23 attr_accessor :tiploc, :nlc, :nlc_description, :tps_description, :stanox, :crs |
Class Method Details
.from_cif(line) ⇒ Object
Initialize a new tiploc from a CIF file line
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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) ⇒ Object
Initialize a new tiploc from a JSON file line
48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |
Instance Method Details
#<=>(other) ⇒ Object
61 62 63 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 61 def <=>(other) hash <=> other&.hash end |
#hash ⇒ Object
65 66 67 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 65 def hash tiploc.dup end |
#to_cif ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 69 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) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rail_feeds/network_rail/schedule/tiploc.rb', line 84 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 |