atco 1.0.2 → 1.0.4
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 +4 -4
- data/lib/atco/version.rb +1 -1
- data/lib/atco.rb +16 -3
- data/spec/atco_spec.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5321b93f293661308b4e7ee41024d24f873e08115c14a0600a45ca50875ca7d
|
4
|
+
data.tar.gz: d31652011de26eb9872d118366e47d07e578d2a1f1459e8b6079219b0e42aafb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09fb7d8d1948d46855e0a07cd9f3739360e85fc048235ef6994b15939ef3e54faabfc4f5399b4076dcb498df0f26528a403f7e10e3532cddf7f55aa13a0f5f44'
|
7
|
+
data.tar.gz: 07f1ed552c5b5278975e309bce0f518efeab83c518ea16fbc88fecff35d6ff80c8650ac1ba1682ff0d53edf5b10a9ce33337fe7309ab8ce79cccc6b2289f4491
|
data/lib/atco/version.rb
CHANGED
data/lib/atco.rb
CHANGED
@@ -9,6 +9,8 @@ require_relative "atco/version"
|
|
9
9
|
|
10
10
|
# Public: Atco is a module that provides a parser for the ATCO-CIF data format.
|
11
11
|
module Atco # rubocop:disable Metrics/ModuleLength
|
12
|
+
class UnidentifiedRecordError < StandardError; end
|
13
|
+
|
12
14
|
class << self # rubocop:disable Metrics/ClassLength
|
13
15
|
@path = nil
|
14
16
|
METHODS = {
|
@@ -21,6 +23,7 @@ module Atco # rubocop:disable Metrics/ModuleLength
|
|
21
23
|
origin: "QO",
|
22
24
|
journey_header: "QS"
|
23
25
|
}.freeze
|
26
|
+
METHODS_BY_RECORD_IDENTITY = METHODS.invert.freeze
|
24
27
|
|
25
28
|
def parse(file) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
26
29
|
@path = File.expand_path(file)
|
@@ -32,13 +35,20 @@ module Atco # rubocop:disable Metrics/ModuleLength
|
|
32
35
|
locations = []
|
33
36
|
journeys = {}
|
34
37
|
header = nil
|
38
|
+
unparsed = []
|
35
39
|
|
36
|
-
data.
|
40
|
+
data.each_with_index do |line, line_number| # rubocop:disable Metrics/BlockLength
|
37
41
|
if line == data.first
|
38
42
|
header = parse_header(line)
|
39
43
|
next
|
40
44
|
end
|
41
|
-
|
45
|
+
|
46
|
+
identifier = line[0, 2]
|
47
|
+
method = METHODS_BY_RECORD_IDENTITY[identifier]
|
48
|
+
|
49
|
+
begin
|
50
|
+
raise UnidentifiedRecordError, "Unidentified record: #{identifier}" unless method
|
51
|
+
|
42
52
|
object = send("parse_#{method}", line)
|
43
53
|
next unless object[:record_identity] && object[:record_identity] == identifier
|
44
54
|
|
@@ -59,9 +69,12 @@ module Atco # rubocop:disable Metrics/ModuleLength
|
|
59
69
|
end
|
60
70
|
end
|
61
71
|
objects << object
|
72
|
+
rescue UnidentifiedRecordError
|
73
|
+
unparsed << { line: line, line_number: line_number }
|
74
|
+
next
|
62
75
|
end
|
63
76
|
end
|
64
|
-
{ header: header, locations: locations, journeys: journeys }
|
77
|
+
{ header: header, locations: locations, journeys: journeys, unparsed: unparsed }
|
65
78
|
end
|
66
79
|
|
67
80
|
def parse_header(string)
|
data/spec/atco_spec.rb
CHANGED
@@ -194,5 +194,27 @@ RSpec.describe Atco do # rubocop:disable Metrics/BlockLength
|
|
194
194
|
json = JSON.parse(data)
|
195
195
|
expect(json).to be_a(Hash)
|
196
196
|
end
|
197
|
+
|
198
|
+
it "should return 17 unparsed lines" do
|
199
|
+
expect(@atco[:unparsed].size).to eq(17)
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should not parse GS records" do
|
203
|
+
expect(@atco[:unparsed][0]).to eq(
|
204
|
+
{
|
205
|
+
line: "GS00001433 N Belfast Metro Ops 7000\n",
|
206
|
+
line_number: 3
|
207
|
+
}
|
208
|
+
)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should not parse GR records" do
|
212
|
+
expect(@atco[:unparsed][1]).to eq(
|
213
|
+
{
|
214
|
+
line: "GR00001433Donegall Square East 7000\n", # rubocop:disable Layout/LineLength
|
215
|
+
line_number: 4
|
216
|
+
}
|
217
|
+
)
|
218
|
+
end
|
197
219
|
end
|
198
220
|
end
|