atco 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91d4d697f6d487218aa3def133f0104257141ed8fb18b93be2c3f0c52ac92a6e
4
- data.tar.gz: 213d51b686a0076c69f26b6d18173dd2b767eaf24db17f7e0cdc011406b94705
3
+ metadata.gz: 215cf54f3257e776c20d54d0177731f06cf62eda409e7763457c709757aa1a52
4
+ data.tar.gz: 97ebd8cf82c779b872f23204079a230aae0d9b159bacdf3db5042cada877a197
5
5
  SHA512:
6
- metadata.gz: fb0ccef50c6a0490c9b87b0b01a7179bec8ca755d594f52193ef6220ef6733e2c8ed600f46043c3a0a38038f3290a8687f1828adfe893dac7dad5c7413b23c89
7
- data.tar.gz: 6ba15c31b4cfb1873577af0fe50c62c6325780d9f9c3c6ddb124cfe91397dd2808382757f1198f492ea6fbbe2a21131e010b49ac80a757f33041a3ff57db1d9f
6
+ metadata.gz: 69b1de96881df1044138cbebe82ea3e22053c47d36aa38dbb39c1018683675eb44e27619be1d29346d5ef156f924c3ee8e408808aec11b7940ad2ca4877dfc25
7
+ data.tar.gz: d14f0b410610dbaf1d2e4e80ce41703becb6fddc99c06bbe3a88500d65bde6b3b44bdfa7768405682c654abf8cb0ecb5470a7589b7f6b978f0933db2e230736e
data/README.md CHANGED
@@ -23,7 +23,7 @@ gem install atco
23
23
  irb
24
24
 
25
25
 
26
- require 'rubygems
26
+ require 'rubygems'
27
27
  require 'atco'
28
28
 
29
29
  result = Atco.parse('filename.cif')
@@ -34,4 +34,4 @@ result = Atco.parse('SVRTMAO009A-20091005.cif) # an example data file in the rep
34
34
  locations: […],
35
35
  journies: {…}
36
36
  }
37
- ```
37
+ ```
data/Rakefile CHANGED
@@ -1,12 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
3
+ require "bundler/gem_tasks"
5
4
 
6
5
  begin
6
+ require "rspec/core/rake_task"
7
7
  RSpec::Core::RakeTask.new(:spec)
8
8
  rescue LoadError
9
- puts 'RSpec, or one of its dependencies, is not available. Install it with: bundle install'
9
+ puts "RSpec, or one of its dependencies, is not available. Install it with: bundle install"
10
10
  end
11
11
 
12
- task default: :spec
12
+ begin
13
+ require "rubocop/rake_task"
14
+ RuboCop::RakeTask.new
15
+ rescue LoadError
16
+ puts "rubocop, or one of its dependencies, is not available. Install it with: bundle install"
17
+ end
18
+
19
+ task default: %i[spec rubocop]
data/lib/atco/journey.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Atco
4
+ # Atco::Journey is a data class to abstract ATCO-CIF Journey records.
4
5
  class Journey
5
6
  attr_accessor :vehicle_type, :registration_number, :identifier, :operator, :route_number, :first_date_of_operation,
6
7
  :running_board, :last_date_of_operation, :school_term_time, :route_direction, :bank_holidays, :stops
7
8
 
8
- def initialize(data)
9
+ def initialize(data) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
9
10
  @mondays = parse_boolean_int data[:operates_on_mondays]
10
11
  @tuesdays = parse_boolean_int data[:operates_on_tuesdays]
11
12
  @wednesdays = parse_boolean_int data[:operates_on_wednesdays]
@@ -61,10 +62,10 @@ module Atco
61
62
  end
62
63
 
63
64
  def parse_boolean_int(string)
64
- string && string == '1' ? true : false
65
+ string && string == "1"
65
66
  end
66
67
 
67
- def to_json(*args)
68
+ def to_json(*attrs) # rubocop:disable Metrics/MethodLength
68
69
  {
69
70
  vehicle_type: @vehicle_type,
70
71
  registration_number: @registration_number,
@@ -78,7 +79,7 @@ module Atco
78
79
  route_direction: @route_direction,
79
80
  bank_holidays: @bank_holidays,
80
81
  stops: @stops
81
- }.to_json(*args)
82
+ }.to_json(*attrs)
82
83
  end
83
84
  end
84
85
  end
data/lib/atco/location.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Atco
4
+ # Atco::Location is a data class to abstract ATCO-CIF Location records.
4
5
  class Location
5
6
  attr_accessor :name, :identifier, :easting, :northing, :gazeteer_code
6
7
 
@@ -12,14 +13,14 @@ module Atco
12
13
  @gazeteer_code = location_header[:gazetteer_code]
13
14
  end
14
15
 
15
- def to_json(*a)
16
+ def to_json(*attrs)
16
17
  {
17
18
  name: @name,
18
19
  identifier: @identifier,
19
20
  easting: @easting,
20
21
  northing: @northing,
21
22
  gazeteer_code: @gazeteer_code
22
- }.to_json(*a)
23
+ }.to_json(*attrs)
23
24
  end
24
25
  end
25
26
  end
data/lib/atco/stop.rb CHANGED
@@ -1,20 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Atco
4
+ # Atco::Stop is a class to abstract ATCO-CIF Origin, Intermediate and Destination (Stop) records.
4
5
  class Stop
5
6
  attr_accessor :bay_number, :location, :timing_point_indicator, :fare_stage_indicator, :published_departure_time,
6
7
  :record_identity
7
8
 
8
9
  def origin?
9
- @record_identity == 'QO'
10
+ @record_identity == "QO"
10
11
  end
11
12
 
12
13
  def intermediate?
13
- @record_identity == 'QI'
14
+ @record_identity == "QI"
14
15
  end
15
16
 
16
17
  def destination?
17
- @record_identity == 'QT'
18
+ @record_identity == "QT"
18
19
  end
19
20
 
20
21
  def initialize(data)
@@ -26,7 +27,7 @@ module Atco
26
27
  @record_identity = data[:record_identity]
27
28
  end
28
29
 
29
- def to_json(*args)
30
+ def to_json(*attrs)
30
31
  {
31
32
  record_identity: @record_identity,
32
33
  location: @location,
@@ -34,7 +35,7 @@ module Atco
34
35
  timing_point_indicator: @timing_point_indicator,
35
36
  fare_stage_indicator: @fare_stage_indicator,
36
37
  bay_number: @bay_number
37
- }.to_json(*args)
38
+ }.to_json(*attrs)
38
39
  end
39
40
  end
40
41
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Atco
4
+ VERSION = "1.0.1"
5
+ end
data/lib/atco.rb CHANGED
@@ -1,31 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__)) unless
4
- $LOAD_PATH.include?(File.dirname(__FILE__)) || $LOAD_PATH.include?(__dir__)
5
-
6
- require 'open3'
7
- require 'tempfile'
8
- require 'atco/location'
9
- require 'atco/journey'
10
- require 'atco/stop'
11
-
12
- module Atco
13
- VERSION = '0.0.1'
14
-
15
- class << self
3
+ require "open3"
4
+ require "tempfile"
5
+ require_relative "atco/location"
6
+ require_relative "atco/journey"
7
+ require_relative "atco/stop"
8
+ require_relative "atco/version"
9
+
10
+ # Public: Atco is a module that provides a parser for the ATCO-CIF data format.
11
+ module Atco # rubocop:disable Metrics/ModuleLength
12
+ class << self # rubocop:disable Metrics/ClassLength
16
13
  @path = nil
17
- @@methods = {
18
- bank_holiday: 'QH',
19
- operator: 'QP',
20
- additional_location_info: 'QB',
21
- location: 'QL',
22
- destination: 'QT',
23
- intermediate: 'QI',
24
- origin: 'QO',
25
- journey_header: 'QS'
26
- }
27
-
28
- def parse(file)
14
+ METHODS = {
15
+ bank_holiday: "QH",
16
+ operator: "QP",
17
+ additional_location_info: "QB",
18
+ location: "QL",
19
+ destination: "QT",
20
+ intermediate: "QI",
21
+ origin: "QO",
22
+ journey_header: "QS"
23
+ }.freeze
24
+
25
+ def parse(file) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
29
26
  @path = File.expand_path(file)
30
27
  data = File.readlines(@path)
31
28
 
@@ -41,13 +38,13 @@ module Atco
41
38
  header = parse_header(line)
42
39
  next
43
40
  end
44
- @@methods.each do |method, identifier|
41
+ METHODS.each do |method, identifier|
45
42
  object = send("parse_#{method}", line)
46
43
  next unless object[:record_identity] && object[:record_identity] == identifier
47
44
 
48
- current_journey = object if object[:record_identity] && object[:record_identity] == @@methods[:journey_header]
49
- if object[:record_identity] && (object[:record_identity] == @@methods[:location] || object[:record_identity] == @@methods[:additional_location_info])
50
- if object[:record_identity] == @@methods[:location]
45
+ current_journey = object if object[:record_identity] && object[:record_identity] == METHODS[:journey_header]
46
+ if object[:record_identity] && (object[:record_identity] == METHODS[:location] || object[:record_identity] == METHODS[:additional_location_info]) # rubocop:disable Layout/LineLength
47
+ if object[:record_identity] == METHODS[:location]
51
48
  current_location = object
52
49
  else
53
50
  locations << Location.new(current_location, object)
@@ -150,7 +147,7 @@ module Atco
150
147
  }
151
148
  end
152
149
 
153
- def parse_journey_header(string)
150
+ def parse_journey_header(string) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
154
151
  {
155
152
  record_identity: string[0, 2],
156
153
  transaction_type: string[2, 1],
data/spec/atco_spec.rb CHANGED
@@ -1,173 +1,174 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "#{File.dirname(__FILE__)}/spec_helper"
4
- require 'json'
4
+ require "json"
5
5
 
6
- describe Atco do
7
- before(:all) do
6
+ describe Atco do # rubocop:disable Metrics/BlockLength
7
+ it "has a version number" do
8
+ expect(Atco::VERSION).not_to be nil
8
9
  end
9
10
 
10
- it 'should output file for debugging!' do
11
- result = Atco.parse('spec/fixtures/example.cif')
12
- File.open('test.output', 'w+') do |f|
11
+ it "should output file for debugging!" do
12
+ result = Atco.parse("spec/fixtures/example.cif")
13
+ File.open("test.output", "w+") do |f|
13
14
  f.flush
14
15
  f.write(JSON.pretty_generate(result))
15
16
  end
16
17
  end
17
18
 
18
- it 'should parse header from fixture' do
19
- result = Atco.parse('spec/fixtures/example.cif')
19
+ it "should parse header from fixture" do
20
+ result = Atco.parse("spec/fixtures/example.cif")
20
21
  expect result[:header] == {
21
- file_type: 'ATCO-CIF',
22
- file_originator: 'Electronic Registration',
23
- source_product: 'MIA 4.20.18',
24
- version: '5.0',
25
- production_datetime: '20090915113809'
22
+ file_type: "ATCO-CIF",
23
+ file_originator: "Electronic Registration",
24
+ source_product: "MIA 4.20.18",
25
+ version: "5.0",
26
+ production_datetime: "20090915113809"
26
27
  }
27
28
  end
28
29
 
29
- it 'should parse locations from fixture' do
30
- result = Atco.parse('spec/fixtures/example.cif')
30
+ it "should parse locations from fixture" do
31
+ result = Atco.parse("spec/fixtures/example.cif")
31
32
  expect result[:header] == {
32
- file_type: 'ATCO-CIF',
33
- file_originator: 'Electronic Registration',
34
- source_product: 'MIA 4.20.18',
35
- version: '5.0',
36
- production_datetime: '20090915113809'
33
+ file_type: "ATCO-CIF",
34
+ file_originator: "Electronic Registration",
35
+ source_product: "MIA 4.20.18",
36
+ version: "5.0",
37
+ production_datetime: "20090915113809"
37
38
  }
38
39
  end
39
40
 
40
- it 'should parse header' do
41
+ it "should parse header" do
41
42
  expect Atco.parse_header("ATCO-CIF0500Electronic Registration MIA 4.20.18 20090915113809\r\n") == {
42
- file_type: 'ATCO-CIF',
43
- version: '5.0',
44
- file_originator: 'Electronic Registration',
45
- source_product: 'MIA 4.20.18',
46
- production_datetime: '20090915113809'
43
+ file_type: "ATCO-CIF",
44
+ version: "5.0",
45
+ file_originator: "Electronic Registration",
46
+ source_product: "MIA 4.20.18",
47
+ production_datetime: "20090915113809"
47
48
  }
48
49
  end
49
50
 
50
- it 'should parse bank holiday' do
51
- expect Atco.parse_bank_holiday('QHN20061225') == {
52
- record_identity: 'QH',
53
- transaction_type: 'N',
54
- date_of_bank_holiday: '20061225'
51
+ it "should parse bank holiday" do
52
+ expect Atco.parse_bank_holiday("QHN20061225") == {
53
+ record_identity: "QH",
54
+ transaction_type: "N",
55
+ date_of_bank_holiday: "20061225"
55
56
  }
56
57
  end
57
58
 
58
- it 'should parse operator' do
59
+ it "should parse operator" do
59
60
  expect Atco.parse_operator("QPNTM Translink Metro Translink Metro \r\n") == {
60
- record_identity: 'QP',
61
- transaction_type: 'N',
62
- operator: 'TM',
63
- operator_short_form: 'Translink Metro',
64
- operator_legal_name: 'Translink Metro'
61
+ record_identity: "QP",
62
+ transaction_type: "N",
63
+ operator: "TM",
64
+ operator_short_form: "Translink Metro",
65
+ operator_legal_name: "Translink Metro"
65
66
  }
66
67
  end
67
68
 
68
- it 'should parse additional location information' do
69
+ it "should parse additional location information" do
69
70
  expect Atco.parse_additional_location_info("QBN700000001252 328622 367433 \r\n") == {
70
- record_identity: 'QB',
71
- transaction_type: 'N',
72
- location: '700000001252',
73
- grid_reference_easting: '328622',
74
- grid_reference_northing: '367433'
71
+ record_identity: "QB",
72
+ transaction_type: "N",
73
+ location: "700000001252",
74
+ grid_reference_easting: "328622",
75
+ grid_reference_northing: "367433"
75
76
  }
76
77
  end
77
78
 
78
- it 'should parse location' do
79
+ it "should parse location" do
79
80
  expect Atco.parse_location("QLN700000001252Conway (River Rd) 1\r\n") == {
80
- record_identity: 'QL',
81
- transaction_type: 'N',
82
- location: '700000001252',
83
- full_location: 'Conway (River Rd)',
84
- gazetteer_code: '1'
81
+ record_identity: "QL",
82
+ transaction_type: "N",
83
+ location: "700000001252",
84
+ full_location: "Conway (River Rd)",
85
+ gazetteer_code: "1"
85
86
  }
86
87
  end
87
88
 
88
89
  # QT7000000012520605 T1F0
89
- it 'should parse destination' do
90
+ it "should parse destination" do
90
91
  expect Atco.parse_destination("QT7000000012520605 T1F0\r\n") == {
91
- record_identity: 'QT',
92
- location: '700000001252',
93
- published_arrival_time: '0605',
94
- bay_number: '',
95
- timing_point_indicator: 'T1',
96
- fare_stage_indicator: 'F0'
92
+ record_identity: "QT",
93
+ location: "700000001252",
94
+ published_arrival_time: "0605",
95
+ bay_number: "",
96
+ timing_point_indicator: "T1",
97
+ fare_stage_indicator: "F0"
97
98
  }
98
99
  end
99
100
 
100
- it 'should parse intermediate' do
101
+ it "should parse intermediate" do
101
102
  expect Atco.parse_intermediate("QI70000000125607120712B T1F0\r\n") == {
102
- record_identity: 'QI',
103
- location: '700000001256',
104
- published_arrival_time: '0712',
105
- published_departure_time: '0712',
106
- activity_flag: 'B',
107
- bay_number: '',
108
- timing_point_indicator: 'T1',
109
- fare_stage_indicator: 'F0'
103
+ record_identity: "QI",
104
+ location: "700000001256",
105
+ published_arrival_time: "0712",
106
+ published_departure_time: "0712",
107
+ activity_flag: "B",
108
+ bay_number: "",
109
+ timing_point_indicator: "T1",
110
+ fare_stage_indicator: "F0"
110
111
  }
111
112
  end
112
113
 
113
- it 'should parse origin' do
114
+ it "should parse origin" do
114
115
  expect Atco.parse_origin("QO7000000012520730 T1F0\r\n") == {
115
- record_identity: 'QO',
116
- location: '700000001252',
117
- published_departure_time: '0730',
118
- bay_number: '',
119
- timing_point_indicator: 'T1',
120
- fare_stage_indicator: 'F0'
116
+ record_identity: "QO",
117
+ location: "700000001252",
118
+ published_departure_time: "0730",
119
+ bay_number: "",
120
+ timing_point_indicator: "T1",
121
+ fare_stage_indicator: "F0"
121
122
  }
122
123
  end
123
124
 
124
- it 'should parse journey header' do
125
+ it "should parse journey header" do
125
126
  expect Atco.parse_journey_header("QSNTM 13986520091005 1111100 9A 9018 0 I\r\n") == {
126
- record_identity: 'QS',
127
- transaction_type: 'N',
128
- operator: 'TM',
129
- unique_journey_identifier: '139865',
130
- first_date_of_operation: '20091005',
131
- last_date_of_operation: '',
132
- operates_on_mondays: '1',
133
- operates_on_tuesdays: '1',
134
- operates_on_wednesdays: '1',
135
- operates_on_thursdays: '1',
136
- operates_on_fridays: '1',
137
- operates_on_saturdays: '0',
138
- operates_on_sundays: '0',
139
- school_term_time: '',
140
- bank_holidays: '',
141
- route_number: '9A',
142
- running_board: '9018',
143
- vehicle_type: '0',
144
- registration_number: '',
145
- route_direction: 'I'
127
+ record_identity: "QS",
128
+ transaction_type: "N",
129
+ operator: "TM",
130
+ unique_journey_identifier: "139865",
131
+ first_date_of_operation: "20091005",
132
+ last_date_of_operation: "",
133
+ operates_on_mondays: "1",
134
+ operates_on_tuesdays: "1",
135
+ operates_on_wednesdays: "1",
136
+ operates_on_thursdays: "1",
137
+ operates_on_fridays: "1",
138
+ operates_on_saturdays: "0",
139
+ operates_on_sundays: "0",
140
+ school_term_time: "",
141
+ bank_holidays: "",
142
+ route_number: "9A",
143
+ running_board: "9018",
144
+ vehicle_type: "0",
145
+ registration_number: "",
146
+ route_direction: "I"
146
147
  }
147
148
  end
148
149
 
149
- describe 'with example.cif' do
150
+ describe "with example.cif" do
150
151
  before(:all) do
151
- @atco = Atco.parse('spec/fixtures/example.cif')
152
+ @atco = Atco.parse("spec/fixtures/example.cif")
152
153
  end
153
154
 
154
- it 'should parse 1 journey' do
155
+ it "should parse 1 journey" do
155
156
  expect @atco[:journeys].size == 1
156
157
  end
157
158
 
158
- it 'should parse journeys into Atco::Joruney objects' do
159
- expect(@atco[:journeys]['139748']).to be_a_kind_of(Atco::Journey)
159
+ it "should parse journeys into Atco::Joruney objects" do
160
+ expect(@atco[:journeys]["139748"]).to be_a_kind_of(Atco::Journey)
160
161
  end
161
162
 
162
- it 'should parse 6 stops for joureny 139748' do
163
- expect @atco[:journeys]['139748'].stops.size == 6
163
+ it "should parse 6 stops for joureny 139748" do
164
+ expect @atco[:journeys]["139748"].stops.size == 6
164
165
  end
165
166
 
166
- it 'should parse 6 stops for joureny 139748' do
167
- expect @atco[:journeys]['139748'].stops.size == 6
167
+ it "should parse 6 stops for joureny 139748" do
168
+ expect @atco[:journeys]["139748"].stops.size == 6
168
169
  end
169
170
 
170
- it 'should parse 2 locations' do
171
+ it "should parse 2 locations" do
171
172
  expect @atco[:locations].size == 2
172
173
  end
173
174
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
4
- require 'rspec'
3
+ require "rubygems"
4
+ require "rspec"
5
5
 
6
6
  require "#{File.dirname(__FILE__)}/../lib/atco"
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atco
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rice
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-04 00:00:00.000000000 Z
11
+ date: 2024-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '13.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '13.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.9'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3.9'
41
41
  description: Simple and opinionated library for parsing ATCO .cif files to JSON with
42
42
  Ruby
43
43
  email: me@davidjrice.co.uk
@@ -48,11 +48,11 @@ extra_rdoc_files:
48
48
  files:
49
49
  - README.md
50
50
  - Rakefile
51
- - VERSION
52
51
  - lib/atco.rb
53
52
  - lib/atco/journey.rb
54
53
  - lib/atco/location.rb
55
54
  - lib/atco/stop.rb
55
+ - lib/atco/version.rb
56
56
  - spec/atco_spec.rb
57
57
  - spec/fixtures/example.cif
58
58
  - spec/fixtures/example.json
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: '0'
73
+ version: 2.7.0
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.0