-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update BLZ data + add Ruby 3.4 support (#254)
- **Update BLZ2 20241209** - **Add ruby 3.4 support**
- Loading branch information
1 parent
501798f
commit 6e1201d
Showing
16 changed files
with
152 additions
and
14,948 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.2.2 | ||
3.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.