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

Update BLZ data + add Ruby 3.4 support #254

Merged
merged 2 commits into from
Jan 23, 2025
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 .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
validate:
strategy:
matrix:
ruby-version: ["2.7", "3.0", "3.1", "3.2"]
ruby-version: ["3.1", "3.2", "3.3", "3.4"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
50 changes: 2 additions & 48 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,8 @@
inherit_from: .rubocop_todo.yml

inherit_gem:
gc_ruboconfig: rubocop.yml
require: rubocop-rails

AllCops:
TargetRubyVersion: 3.2

# Limit lines to 90 characters.
Layout/LineLength:
Max: 90

Metrics/ClassLength:
Max: 400

# Avoid single-line methods.
Style/SingleLineMethods:
AllowIfMethodIsEmpty: true

# Wants underscores in all large numbers. Pain in the ass for things like
# unix timestamps.
Style/NumericLiterals:
Enabled: false

# Wants you to use the same argument names for every reduce. This seems kinda
# naff compared to naming them semantically
Style/SingleLineBlockParams:
Enabled: false

Style/SignalException:
EnforcedStyle: 'only_raise'

# Wants to exclude accents from comments
Style/AsciiComments:
Enabled: false

# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 25

# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 400

Layout/DotPosition:
EnforcedStyle: 'trailing'

# Wants to to lock to Ruby 2.4 as specified here but as this is a public gem
# this is quite aggressive.
Gemspec/RequiredRubyVersion:
Enabled: false

Rails/Blank:
Enabled: false
NewCops: enable
62 changes: 27 additions & 35 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,69 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-08-25 10:15:35 UTC using RuboCop version 0.89.1.
# on 2025-01-23 15:25:02 UTC using RuboCop version 1.71.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 8
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 25

# Offense count: 2
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 8
# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'ibandit.gemspec'

# Offense count: 1
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
# Configuration parameters: LengthThreshold.
Metrics/CollectionLiteralLength:
Exclude:
- 'lib/ibandit/sweden/bank_lookup.rb'
- 'lib/ibandit/german_details_converter.rb'

# Offense count: 1
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'lib/ibandit/german_details_converter.rb'

# Offense count: 1
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- '**/spec/features/**/*'
- '**/spec/requests/**/*'
- '**/spec/routing/**/*'
- '**/spec/system/**/*'
- '**/spec/views/**/*'
- 'spec/ibandit/structure_spec.rb'

# Offense count: 1
# Configuration parameters: Max.
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Exclude:
- 'spec/ibandit/iban_spec.rb'
Max: 6

# Offense count: 1
RSpec/ExpectInHook:
Exclude:
- 'spec/ibandit/german_details_converter_spec.rb'

# Offense count: 12
# Offense count: 15
RSpec/MultipleExpectations:
Max: 2

# Offense count: 182
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 7

# Offense count: 20
# Configuration parameters: IgnoreSharedExamples.
# Offense count: 26
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/ibandit/iban_spec.rb'

# Offense count: 368
# Offense count: 177
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 6

# Offense count: 18
RSpec/ScatteredSetup:
Exclude:
- 'spec/ibandit/iban_assembler_spec.rb'
- 'spec/ibandit/iban_spec.rb'
Max: 5

# Offense count: 13
# Offense count: 37
RSpec/SubjectStub:
Exclude:
- 'spec/ibandit/iban_spec.rb'
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
3.4.1
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 1.22.0 - January 22, 2025

- Remove support for Ruby < 3.1, add support for Ruby >= 3.4
- Update BLZ2 data - BLZ_20241209
- Update IBAN structures for `BE`, `ES`, `XK`.
- Add partial support for `SO`, `NI`, `FK`, `OM`, `YE` IBANs.

Expand Down
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
source 'https://rubygems.org'

gemspec

group :development, :test do
gem "gc_ruboconfig", "~> 5.0"
gem "nokogiri", "~> 1.6"
gem "pry", "~> 0.13"
gem "pry-byebug", "~> 3.10"
gem "rspec", "~> 3.12"
gem "rspec-its", "~> 1.2"
gem "sax-machine", "~> 1.3"
end
50 changes: 26 additions & 24 deletions bin/build_german_iban_rules.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Script for parsing the Bankleitzahl file (BLZ2.xml) from the Deutsche Bundesbank.
require "yaml"
require "sax-machine"

class BLZRecord
include SAXMachine
element "BLZ", as: :bank_code
element "Merkmal", as: :primary_record
element "PruefZiffMeth", as: :check_digit_rule
element "IBANRegel", as: :iban_rule
end

# Script for parsing the Bankleitzahl file (BLZ2.txt) from the Deutsche
# Bundesbank.
require 'yaml'

BLZ_FIELDS = {
bank_code: { position: 0, length: 8 },
primary_record: { position: 8, length: 1 },
check_digit_rule: { position: 150, length: 2 },
iban_rule: { position: 168, length: 6 }
}.freeze

def parse_line(line)
BLZ_FIELDS.each_with_object({}) do |(field, details), hash|
hash[field] = line.slice(details[:position], details[:length])
end
class BLZFile
include SAXMachine
elements "BLZEintrag", as: :records, class: BLZRecord
end

def get_iban_rules(blz2_file)
blz2_file.each_with_object({}) do |line, hash|
bank_details = parse_line(line)

next if bank_details.delete(:primary_record) == '2'
BLZFile.parse(blz2_file).records.each_with_object({}) do |bank_details, hash|
next if bank_details.primary_record == "2"

hash[bank_details.delete(:bank_code)] = bank_details
hash[bank_details.bank_code] = {
check_digit_rule: bank_details.check_digit_rule,
iban_rule: bank_details.iban_rule,
}
end
end

# Only parse the files if this file is run as an executable (not required in,
# as it is in the specs)
if __FILE__ == $PROGRAM_NAME
blz2_file = File.open(File.expand_path('../../data/raw/BLZ2.txt', __FILE__))
blz2_file = File.read(File.expand_path("../data/raw/BLZ2.xml", __dir__))
iban_rules = get_iban_rules(blz2_file)

output_file_path = File.expand_path(
'../../data/german_iban_rules.yml',
__FILE__
"../data/german_iban_rules.yml",
__dir__,
)

File.open(output_file_path, 'w') { |f| f.write(iban_rules.to_yaml) }
File.open(output_file_path, "w") { |f| f.write(iban_rules.to_yaml) }
end
Loading
Loading