Skip to content

Commit

Permalink
remove slice from postcode valie in build_printable_address --update …
Browse files Browse the repository at this point in the history
…gem versions in gemspec --add dvla-lint --rubocop fixes
  • Loading branch information
Mark Isaac committed Oct 30, 2024
1 parent 222f8de commit e6bcaed
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 28 deletions.
7 changes: 6 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
inherit_gem:
dvla-lint: '.rubocop.yml'

AllCops:
TargetRubyVersion: 3.0.0
NewCops: enable
SuggestExtensions: false

Layout/LineLength:
Max: 180
Expand All @@ -8,7 +13,7 @@ Metrics/AbcSize:
Enabled: false

Metrics/BlockLength:
IgnoredMethods:
AllowedMethods:
- 'describe'
- 'context'

Expand Down
4 changes: 1 addition & 3 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ require 'postman_paf'
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
# Use binding.irb

require 'irb'
IRB.start(__FILE__)
4 changes: 2 additions & 2 deletions lib/postman_paf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(paf_address_data:, max_line_length: nil, logging: false)
@max_line_length = if max_line_length.is_a?(Integer) || max_line_length.is_a?(String)
max_line_length.to_i.positive? ? max_line_length.to_i : nil
end
@logging = logging.is_a?(TrueClass) ? true : false
@logging = logging.is_a?(TrueClass)
end

# Handles conversion of single or multiple PAF addresses (i.e. single
Expand All @@ -34,7 +34,7 @@ def convert
converted_addresses.count.eql?(1) ? converted_addresses.pop : converted_addresses
end

private
private

# Converts a single PAF address to printable format after determining
# applicable rule and exception(s). Truncation and logging optional.
Expand Down
2 changes: 1 addition & 1 deletion lib/postman_paf/exceptions/rule_6_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.exception_to_apply_rule6(paf_address:)
:no_exception
end

premise_element_exception = "#{SimpleSymbolize.snakeize(premise_element)}_#{exception}".to_sym
premise_element_exception = :"#{SimpleSymbolize.snakeize(premise_element)}_#{exception}"
exceptions << premise_element_exception
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/postman_paf/printable_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def as_json
'postcode' => @postcode,
'country' => @country,
'language' => @language,
'dps' => @dps
'dps' => @dps,
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/postman_paf/rules/address_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def self.build_printable_address(paf_address:, lines:)
lines.each_with_index do |line, index|
line_number = index + 1
line = line.to_s if line.is_a?(Integer)
printable_address.send("line#{line_number}=", line) if line_number >= 1 && line_number <= 5
printable_address.send(:"line#{line_number}=", line) if line_number >= 1 && line_number <= 5
end

printable_address.postcode = paf_address[POSTCODE].slice(0..7)
printable_address.postcode = paf_address[POSTCODE]
printable_address.country = paf_address[COUNTRY]
printable_address.language = paf_address[LANGUAGE]
printable_address.dps = paf_address[DPS]
Expand Down
4 changes: 2 additions & 2 deletions lib/postman_paf/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def validate
nil
end

private
private

# Verifies input of single Hash contains required address elements.
# @raise [ArgumentError] if Hash is missing required address elements.
Expand Down Expand Up @@ -59,7 +59,7 @@ def validate_multiple_addresses
# @return [Boolean] whether both keys were found.
def criteria_for_paf_address?(hash:)
hash = hash.transform_keys { |k| SimpleSymbolize.camelize(k).to_s }
hash.keys.include?(POST_TOWN) && hash.keys.include?(POSTCODE)
hash.key?(POST_TOWN) && hash.key?(POSTCODE)
end
end
end
2 changes: 1 addition & 1 deletion lib/postman_paf/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module PostmanPAF
VERSION = '0.4.2'
VERSION = '0.5.0'
end
21 changes: 10 additions & 11 deletions postman_paf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ Gem::Specification.new do |spec|
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.require_paths = %w[lib]

spec.add_development_dependency 'bundler-audit', '~> 0.9'
spec.add_development_dependency 'hash_miner', '~> 1.1'
spec.add_development_dependency 'pry', '~> 0.14'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.12'
spec.add_development_dependency 'rubocop', '~> 1.54'
spec.add_development_dependency 'simplecov', '~> 0.22'
spec.add_development_dependency 'simplecov-console', '~> 0.9'

spec.add_runtime_dependency 'simple_symbolize', '~> 4.0'
spec.add_dependency 'bundler-audit', '~> 0.9.2'
spec.add_dependency 'dvla-lint', '~> 1.8.0'
spec.add_dependency 'hash_miner', '~> 1.1.3'
spec.add_dependency 'rake', '~> 13.2.1'
spec.add_dependency 'rspec', '~> 3.13.0'
spec.add_dependency 'rubocop', '~> 1.67.0'
spec.add_dependency 'simplecov', '~> 0.22.0'
spec.add_dependency 'simplecov-console', '~> 0.9.2'
spec.add_dependency 'simple_symbolize', '~> 4.0'
end
4 changes: 2 additions & 2 deletions spec/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
postcode: 'SA99 1BN',
country: 'Wales',
language: 'EN',
dps: '1A'
dps: '1A',
}
end

Expand All @@ -40,7 +40,7 @@
postcode: 'SA99 1BN',
dps: '1A',
language: 'EN',
country: 'WALES'
country: 'WALES',
}, max_line_length: 10)
expected_printable_address = { 'line1' => '1A EXAMPLE',
'line5' => 'EXAMPLE TO',
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

require 'hash_miner'
require 'logger'
require 'pry'
require 'postman_paf'
require 'simple_symbolize'

Expand Down
2 changes: 1 addition & 1 deletion spec/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
end

it 'will error on input of Array of Hashes missing required keys' do
input_array1 = [{ postTown: 'Valid key', postcode: 'Also valid key' }, { postTown: 'Valid key', 'place': 'Invalid key' }]
input_array1 = [{ postTown: 'Valid key', postcode: 'Also valid key' }, { postTown: 'Valid key', place: 'Invalid key' }]
input_array2 = [{ region: 'Invalid key', postcode: 'Valid key' }, { postTown: 'Valid key', postcode: 'Also valid key' }]

expect { PostmanPAF::Validator.new(input: input_array1).validate }.to raise_error(ArgumentError, MISSING_REQUIRED_HASH_KEYS_MSG)
Expand Down

0 comments on commit e6bcaed

Please sign in to comment.