commit
94b602f2f2
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3']
|
ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
@ -1 +1 @@
|
|||||||
3.0.2
|
3.4.3
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
## 0.2.0
|
## 1.0.0
|
||||||
|
|
||||||
- support Ruby 2.7+
|
- Drop bank-contact, use iban-tools (@Joerg-Seitz)
|
||||||
|
- Inline BIC validation from bank-contact
|
||||||
|
- Support Ruby 3.4
|
||||||
|
29
Gemfile.lock
29
Gemfile.lock
@ -1,28 +1,30 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
girocode (0.2.0)
|
girocode (1.0.0)
|
||||||
bank-contact
|
bigdecimal
|
||||||
|
iban-tools
|
||||||
rqrcode
|
rqrcode
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
bank-contact (0.0.6)
|
bigdecimal (3.2.1)
|
||||||
chunky_png (1.4.0)
|
chunky_png (1.4.0)
|
||||||
docile (1.4.0)
|
docile (1.4.1)
|
||||||
minitest (5.14.4)
|
iban-tools (1.2.1)
|
||||||
rake (13.0.6)
|
minitest (5.25.5)
|
||||||
rqrcode (2.1.0)
|
rake (13.3.0)
|
||||||
|
rqrcode (3.1.0)
|
||||||
chunky_png (~> 1.0)
|
chunky_png (~> 1.0)
|
||||||
rqrcode_core (~> 1.0)
|
rqrcode_core (~> 2.0)
|
||||||
rqrcode_core (1.2.0)
|
rqrcode_core (2.0.0)
|
||||||
simplecov (0.21.2)
|
simplecov (0.22.0)
|
||||||
docile (~> 1.1)
|
docile (~> 1.1)
|
||||||
simplecov-html (~> 0.11)
|
simplecov-html (~> 0.11)
|
||||||
simplecov_json_formatter (~> 0.1)
|
simplecov_json_formatter (~> 0.1)
|
||||||
simplecov-html (0.12.3)
|
simplecov-html (0.13.1)
|
||||||
simplecov_json_formatter (0.1.3)
|
simplecov_json_formatter (0.1.4)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
@ -32,6 +34,3 @@ DEPENDENCIES
|
|||||||
minitest
|
minitest
|
||||||
rake
|
rake
|
||||||
simplecov
|
simplecov
|
||||||
|
|
||||||
BUNDLED WITH
|
|
||||||
2.2.22
|
|
||||||
|
@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|||||||
s.files = Dir['{lib}/**/*.rb', 'LICENSE', 'README.md', 'CHANGELOG.md']
|
s.files = Dir['{lib}/**/*.rb', 'LICENSE', 'README.md', 'CHANGELOG.md']
|
||||||
s.require_paths = ['lib']
|
s.require_paths = ['lib']
|
||||||
|
|
||||||
|
s.add_dependency 'bigdecimal'
|
||||||
s.add_dependency 'rqrcode'
|
s.add_dependency 'rqrcode'
|
||||||
s.add_dependency 'bank-contact'
|
s.add_dependency 'iban-tools'
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
require 'bigdecimal'
|
require 'bigdecimal'
|
||||||
require 'bank/contact'
|
require 'iban-tools'
|
||||||
require 'rqrcode'
|
require 'rqrcode'
|
||||||
|
|
||||||
require_relative 'girocode/version'
|
require_relative 'girocode/version'
|
||||||
|
require_relative 'girocode/bic'
|
||||||
require_relative 'girocode/code'
|
require_relative 'girocode/code'
|
||||||
|
|
||||||
module Girocode
|
module Girocode
|
||||||
|
67
lib/girocode/bic.rb
Normal file
67
lib/girocode/bic.rb
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# derived from bank-contact/bic by Kevin
|
||||||
|
|
||||||
|
module Girocode
|
||||||
|
class BIC
|
||||||
|
REGEX = /\A([A-Z]{4})([A-Z]{2})([A-Z0-9]{2})([A-Z0-9]{3})?\z/.freeze
|
||||||
|
|
||||||
|
def self.valid?(code)
|
||||||
|
new(code).valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(code)
|
||||||
|
@code = code.to_s.gsub(/\s+/, '').upcase
|
||||||
|
end
|
||||||
|
|
||||||
|
def bank_code
|
||||||
|
@code[0..3]
|
||||||
|
end
|
||||||
|
|
||||||
|
def country_code
|
||||||
|
@code[4..5]
|
||||||
|
end
|
||||||
|
|
||||||
|
def location_code
|
||||||
|
@code[6..7]
|
||||||
|
end
|
||||||
|
|
||||||
|
def branch_code
|
||||||
|
@code[8..10]
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(formatted = false)
|
||||||
|
formatted ? to_formatted_str : @code
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_formatted_str
|
||||||
|
"#{bank_code} #{country_code} #{location_code} #{branch_code}".strip
|
||||||
|
end
|
||||||
|
|
||||||
|
def test?
|
||||||
|
location_code[1] == '0'
|
||||||
|
end
|
||||||
|
|
||||||
|
def passive?
|
||||||
|
location_code[1] == '1'
|
||||||
|
end
|
||||||
|
|
||||||
|
def reverse_billing?
|
||||||
|
location_code[1] == '2'
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid?
|
||||||
|
valid_format? && valid_location_code? && valid_branch_code?
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_format?
|
||||||
|
REGEX.match?(@code)
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_location_code?
|
||||||
|
!location_code.start_with?('0', '1') && !location_code.end_with?('O')
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_branch_code?
|
||||||
|
branch_code.empty? || branch_code == 'XXX' || !branch_code.start_with?('X')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -24,7 +24,7 @@ module Girocode
|
|||||||
if value.nil?
|
if value.nil?
|
||||||
@bic = nil
|
@bic = nil
|
||||||
else
|
else
|
||||||
bic = Bank::BIC.new(value)
|
bic = BIC.new(value)
|
||||||
raise ArgumentError, "Invalid BIC #{value.inspect}" unless bic.valid?
|
raise ArgumentError, "Invalid BIC #{value.inspect}" unless bic.valid?
|
||||||
@bic = bic.to_s
|
@bic = bic.to_s
|
||||||
end
|
end
|
||||||
@ -39,9 +39,9 @@ module Girocode
|
|||||||
end
|
end
|
||||||
|
|
||||||
def iban=(value)
|
def iban=(value)
|
||||||
iban = Bank::IBAN.new(value)
|
raise ArgumentError, "Invalid IBAN #{value.inspect}" unless IBANTools::IBAN.valid?(value)
|
||||||
raise ArgumentError, "Invalid IBAN #{value.inspect}" unless iban.valid?
|
|
||||||
@iban = iban.to_s
|
@iban = value
|
||||||
end
|
end
|
||||||
|
|
||||||
def currency=(value)
|
def currency=(value)
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
module Girocode
|
module Girocode
|
||||||
VERSION = "0.2.0"
|
VERSION = "1.0.0"
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@ require_relative 'test_helper'
|
|||||||
|
|
||||||
class GirocodeTest < Minitest::Test
|
class GirocodeTest < Minitest::Test
|
||||||
def test_that_it_has_a_version_number
|
def test_that_it_has_a_version_number
|
||||||
refute_nil ::Girocode::VERSION
|
refute_nil Girocode::VERSION
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_girocode
|
def test_girocode
|
||||||
@ -11,6 +11,12 @@ class GirocodeTest < Minitest::Test
|
|||||||
assert_equal data(:data), code.to_ascii
|
assert_equal data(:data), code.to_ascii
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_bic
|
||||||
|
assert_raises ArgumentError do
|
||||||
|
Girocode.new(bic: 'FOOBAR', name: 'Franz Mustermänn', iban: 'DE71110220330123456789', currency: :eur, amount: 12.3, purpose: 'GDDS', creditor_reference: 'RF18539007547034')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def data(name)
|
def data(name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user