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

build: rubocop fixes and deprecation of .rubocop_todo.yml file #10

Merged
merged 25 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
418fca2
fix: rubocop warnings and update TODOs
davidjrice Apr 11, 2024
89a7732
build: change rubocop config to prefer double quotes for string literals
davidjrice Apr 11, 2024
1bedd48
build: add specific ignore for rubocop Layout/LineLength offence
davidjrice Apr 11, 2024
cd244a4
fix: rubocop Gemspec/DuplicatedAssignment offence
davidjrice Apr 11, 2024
7b4aae7
fix: rubocop Gemspec/RequiredRubyVersion offence
davidjrice Apr 11, 2024
5b91c8a
build: remove Layout/LineLength override from rubocop todo
davidjrice Apr 11, 2024
dd67ed6
fix: gemspec definition, use spec as variable for clarity
davidjrice Apr 11, 2024
175c679
fix: rubocop Style/ClassVars offence
davidjrice Apr 11, 2024
566f3dc
fix: rubocop Naming/MethodParameterName offence and default to using …
davidjrice Apr 11, 2024
e391e5d
build: add specific disable for rubocop Metrics/BlockLength in specs
davidjrice Apr 11, 2024
dccd254
build: add specific ignore for rubocop Metrics/ClassLength offence
davidjrice Apr 11, 2024
6b19782
build: add specific ignore for rubocop Metrics/ModuleLength offence
davidjrice Apr 11, 2024
15ae51a
build: add specific ignore for rubocop Metrics/PerceivedComplexity of…
davidjrice Apr 11, 2024
ad205f4
build: add specific ignore for rubocop Metrics/CyclomaticComplexity o…
davidjrice Apr 11, 2024
3aa30b3
build: add specific ignores for rubocop Metrics/AbcSize offences
davidjrice Apr 11, 2024
9baa521
build: add specific ignore for rubocop Metrics/MethodLength offence
davidjrice Apr 11, 2024
18b7888
docs: add top-level documentation comments to fix rubocop Style/Docum…
davidjrice Apr 11, 2024
3958d29
build: remove rubocop TODO file as all offences are fixed or specific…
davidjrice Apr 11, 2024
e64f32c
build: remove rubocop todo file reference
davidjrice Apr 11, 2024
e07b4b4
build: add rubocop to the default rake task
davidjrice Apr 11, 2024
fb63d18
bump: version 1.0.1
davidjrice Apr 11, 2024
2dfbaa0
fix: gemspec syntax
davidjrice Apr 11, 2024
528be5b
fix: rubocop Style/StringLiterals offence
davidjrice Apr 11, 2024
e298bdb
build: specify version numbers for dev dependencies rake and rspec
davidjrice Apr 11, 2024
2c1156a
build: ignore .gem files
davidjrice Apr 11, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ test.output
fixture.output
pkg/*
checksums/*
*.gem
26 changes: 25 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.7
SuggestExtensions: false
NewCops: enable

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes

Layout/LineLength:
Max: 120

# TODO: Enable this cop after figuring out why it is failing even when mfa required is set to true
Gemspec/RequireMFA:
Enabled: false


# NOTE: I think I actually prefer to have the development dependencies in the gemspec as they
# are therefore visible in Rubygems.org
Gemspec/DevelopmentDependencies:
Enabled: false
87 changes: 0 additions & 87 deletions .rubocop_todo.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

gem 'rubocop', require: false
gem "rubocop", require: false
15 changes: 11 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require "bundler/gem_tasks"

begin
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
puts 'RSpec, or one of its dependencies, is not available. Install it with: bundle install'
puts "RSpec, or one of its dependencies, is not available. Install it with: bundle install"
end

task default: :spec
begin
require "rubocop/rake_task"
RuboCop::RakeTask.new
rescue LoadError
puts "rubocop, or one of its dependencies, is not available. Install it with: bundle install"
end

task default: %i[spec rubocop]
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

33 changes: 17 additions & 16 deletions atco.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

require_relative "lib/atco/version"

Gem::Specification.new do |s|
s.name = 'atco'
s.version = Atco::VERSION
s.description = 'Simple and opinionated library for parsing ATCO .cif files to JSON with Ruby'
s.summary = 'Parse ATCO .cif files to JSON with Ruby'
s.homepage = 'http://github.com/davidjrice/atco'
s.license = 'MIT'
s.authors = ['David Rice']
s.email = '[email protected]'
s.files = s.files = Dir['{lib,spec}/**/*', 'README.md', 'Rakefile', 'VERSION']
s.extra_rdoc_files = [
'README.md'
Gem::Specification.new do |spec|
spec.name = "atco"
spec.version = Atco::VERSION
spec.description = "Simple and opinionated library for parsing ATCO .cif files to JSON with Ruby"
spec.summary = "Parse ATCO .cif files to JSON with Ruby"
spec.homepage = "http://github.com/davidjrice/atco"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.7.0"
spec.authors = ["David Rice"]
spec.email = "[email protected]"
spec.files = Dir["{lib,spec}/**/*", "README.md", "Rakefile", "VERSION"]
spec.extra_rdoc_files = [
"README.md"
]
s.rdoc_options = ['--charset=UTF-8']
s.require_paths = ['lib']
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
spec.rdoc_options = ["--charset=UTF-8"]
spec.require_paths = ["lib"]
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.9"
end
53 changes: 27 additions & 26 deletions lib/atco.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
# frozen_string_literal: true

require 'open3'
require 'tempfile'
require_relative 'atco/location'
require_relative 'atco/journey'
require_relative 'atco/stop'
require_relative 'atco/version'

module Atco
class << self
require "open3"
require "tempfile"
require_relative "atco/location"
require_relative "atco/journey"
require_relative "atco/stop"
require_relative "atco/version"

# Public: Atco is a module that provides a parser for the ATCO-CIF data format.
module Atco # rubocop:disable Metrics/ModuleLength
class << self # rubocop:disable Metrics/ClassLength
@path = nil
@@methods = {
bank_holiday: 'QH',
operator: 'QP',
additional_location_info: 'QB',
location: 'QL',
destination: 'QT',
intermediate: 'QI',
origin: 'QO',
journey_header: 'QS'
}

def parse(file)
METHODS = {
bank_holiday: "QH",
operator: "QP",
additional_location_info: "QB",
location: "QL",
destination: "QT",
intermediate: "QI",
origin: "QO",
journey_header: "QS"
}.freeze

def parse(file) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
@path = File.expand_path(file)
data = File.readlines(@path)

Expand All @@ -37,13 +38,13 @@ def parse(file)
header = parse_header(line)
next
end
@@methods.each do |method, identifier|
METHODS.each do |method, identifier|
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])
if object[:record_identity] == @@methods[:location]
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)
Expand Down Expand Up @@ -146,7 +147,7 @@ def parse_origin(string)
}
end

def parse_journey_header(string)
def parse_journey_header(string) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
{
record_identity: string[0, 2],
transaction_type: string[2, 1],
Expand Down
9 changes: 5 additions & 4 deletions lib/atco/journey.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# frozen_string_literal: true

module Atco
# Atco::Journey is a data class to abstract ATCO-CIF Journey records.
class Journey
attr_accessor :vehicle_type, :registration_number, :identifier, :operator, :route_number, :first_date_of_operation,
:running_board, :last_date_of_operation, :school_term_time, :route_direction, :bank_holidays, :stops

def initialize(data)
def initialize(data) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@mondays = parse_boolean_int data[:operates_on_mondays]
@tuesdays = parse_boolean_int data[:operates_on_tuesdays]
@wednesdays = parse_boolean_int data[:operates_on_wednesdays]
Expand Down Expand Up @@ -61,10 +62,10 @@ def sundays?
end

def parse_boolean_int(string)
string && string == '1' ? true : false
string && string == "1"
end

def to_json(*args)
def to_json(*attrs) # rubocop:disable Metrics/MethodLength
{
vehicle_type: @vehicle_type,
registration_number: @registration_number,
Expand All @@ -78,7 +79,7 @@ def to_json(*args)
route_direction: @route_direction,
bank_holidays: @bank_holidays,
stops: @stops
}.to_json(*args)
}.to_json(*attrs)
end
end
end
5 changes: 3 additions & 2 deletions lib/atco/location.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

module Atco
# Atco::Location is a data class to abstract ATCO-CIF Location records.
class Location
attr_accessor :name, :identifier, :easting, :northing, :gazeteer_code

Expand All @@ -12,14 +13,14 @@ def initialize(location_header, additional_location_information)
@gazeteer_code = location_header[:gazetteer_code]
end

def to_json(*a)
def to_json(*attrs)
{
name: @name,
identifier: @identifier,
easting: @easting,
northing: @northing,
gazeteer_code: @gazeteer_code
}.to_json(*a)
}.to_json(*attrs)
end
end
end
11 changes: 6 additions & 5 deletions lib/atco/stop.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# frozen_string_literal: true

module Atco
# Atco::Stop is a class to abstract ATCO-CIF Origin, Intermediate and Destination (Stop) records.
class Stop
attr_accessor :bay_number, :location, :timing_point_indicator, :fare_stage_indicator, :published_departure_time,
:record_identity

def origin?
@record_identity == 'QO'
@record_identity == "QO"
end

def intermediate?
@record_identity == 'QI'
@record_identity == "QI"
end

def destination?
@record_identity == 'QT'
@record_identity == "QT"
end

def initialize(data)
Expand All @@ -26,15 +27,15 @@ def initialize(data)
@record_identity = data[:record_identity]
end

def to_json(*args)
def to_json(*attrs)
{
record_identity: @record_identity,
location: @location,
published_departure_time: @published_departure_time,
timing_point_indicator: @timing_point_indicator,
fare_stage_indicator: @fare_stage_indicator,
bay_number: @bay_number
}.to_json(*args)
}.to_json(*attrs)
end
end
end
4 changes: 2 additions & 2 deletions 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.0'
end
VERSION = "1.0.1"
end
Loading
Loading