Skip to content

Commit

Permalink
refactor: main parsing logic (#3)
Browse files Browse the repository at this point in the history
* refactor(lib/atco.rb): simplify main parsing logic and remove unnecessary defensive code
* docs: update CONTRIBUTORS.md
* release: bump version 1.0.6

---------

Co-authored-by: Martin Sidaway <[email protected]>
  • Loading branch information
davidjrice and martinjos authored Apr 12, 2024
1 parent d492205 commit 7d1c84b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
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

0 comments on commit 7d1c84b

Please sign in to comment.