Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: main parsing logic #3

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pkg/*
checksums/*
*.gem
spec/artefacts/test.json
.rspec_status
.rspec_status
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

* David Rice [@davidjrice](https://github.com/davidjrice)
* Thomas Buckley-Houston [@tombh](https://github.com/tombh)
* Martin Sidaway [@martinjos](https://github.com/martinjos)
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
atco (1.0.5)
atco (1.0.6)

GEM
remote: https://rubygems.org/
Expand Down
17 changes: 9 additions & 8 deletions lib/atco.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def parse(file) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity,
unparsed = []

data.each_with_index do |line, line_number| # rubocop:disable Metrics/BlockLength
if line == data.first
if line_number.zero?
header = parse_header(line)
next
end
Expand All @@ -52,13 +52,13 @@ def parse(file) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity,
object = send("parse_#{method}", line)
next unless object[:record_identity] && object[:record_identity] == identifier

current_journey = object if object[:record_identity] && object[:record_identity] == METHODS[:journey_header]
if object[:record_identity] && (object[:record_identity] == METHODS[:location] || object[:record_identity] == METHODS[:additional_location_info]) # rubocop:disable Layout/LineLength
if object[:record_identity] == METHODS[:location]
current_location = object
else
locations << Location.new(current_location, object)
end
case method
when :journey_header
current_journey = object
when :location
current_location = object
when :additional_location_info
locations << Location.new(current_location, object)
end

if current_journey
Expand All @@ -73,6 +73,7 @@ def parse(file) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity,
unparsed << { line: line, line_number: line_number }
next
end
objects << object
end
{ header: header, locations: locations, journeys: journeys, unparsed: unparsed }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/atco/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Atco
VERSION = "1.0.5"
VERSION = "1.0.6"
end
Loading