bsb 0.0.15 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +19 -0
- data/.github/workflows/release.yml +57 -0
- data/.github/workflows/update-database.yml +33 -0
- data/.gitignore +5 -0
- data/.release-please-manifest.json +1 -0
- data/.rubocop.yml +16 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +61 -0
- data/Gemfile +2 -0
- data/README.md +4 -0
- data/Rakefile +12 -3
- data/bsb.gemspec +10 -1
- data/config/bsb_bank_list.json +1 -1
- data/config/bsb_db.json +1 -1
- data/lib/auspaynet/client.rb +38 -0
- data/lib/bsb/bank_list_generator.rb +6 -13
- data/lib/bsb/base_generator.rb +21 -0
- data/lib/bsb/database_generator.rb +10 -14
- data/lib/bsb/version.rb +3 -1
- data/lib/bsb.rb +12 -8
- data/lib/bsb_number_validator.rb +3 -4
- data/lib/tasks/bsb_tasks.rake +19 -20
- data/test/bsb_number_validator_test.rb +10 -0
- data/test/bsb_test.rb +28 -0
- data/test/test_helper.rb +13 -0
- metadata +45 -7
- data/.github/workflows/gem-push.yml +0 -45
- data/Gemfile.lock +0 -36
data/lib/auspaynet/client.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'net/ftp'
|
2
4
|
|
3
5
|
module Auspaynet
|
4
6
|
class Client
|
7
|
+
MONTHS = %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec].freeze
|
8
|
+
|
5
9
|
def initialize(host)
|
6
10
|
@host = host
|
7
11
|
@ftp = Net::FTP.new(@host)
|
@@ -15,5 +19,39 @@ module Auspaynet
|
|
15
19
|
ensure
|
16
20
|
@ftp.chdir('/')
|
17
21
|
end
|
22
|
+
|
23
|
+
def list(dir:, matching_filename:, file_format: 'csv')
|
24
|
+
@ftp.chdir(dir)
|
25
|
+
files = @ftp.nlst.select do |f|
|
26
|
+
f.include?(matching_filename) &&
|
27
|
+
f.include?(file_format) &&
|
28
|
+
f.include?(current_year)
|
29
|
+
end
|
30
|
+
|
31
|
+
extract_latest_files(files: files, file_format: file_format)
|
32
|
+
ensure
|
33
|
+
@ftp.chdir('/')
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def current_year
|
39
|
+
Time.now.strftime('%y')
|
40
|
+
end
|
41
|
+
|
42
|
+
def extract_latest_files(files:, file_format:)
|
43
|
+
files.sort_by do |filename|
|
44
|
+
file_for_month(filename: filename, file_format: file_format)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def file_for_month(filename:, file_format:)
|
49
|
+
month_from_filename = filename.gsub(/(#{filename}|#{file_format}|\W|\d)/, '')
|
50
|
+
month_number(month_from_filename)
|
51
|
+
end
|
52
|
+
|
53
|
+
def month_number(month_from_filename)
|
54
|
+
MONTHS.find_index(month_from_filename)
|
55
|
+
end
|
18
56
|
end
|
19
57
|
end
|
@@ -1,24 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'csv'
|
3
|
-
require '
|
4
|
+
require 'bsb/base_generator'
|
4
5
|
|
5
6
|
module BSB
|
6
|
-
class BankListGenerator
|
7
|
-
def initialize(hash)
|
8
|
-
@hash = hash
|
9
|
-
end
|
10
|
-
|
11
|
-
def json
|
12
|
-
JSON.dump(@hash)
|
13
|
-
end
|
14
|
-
|
7
|
+
class BankListGenerator < BaseGenerator
|
15
8
|
def self.load_file(filename)
|
16
9
|
client = ::Auspaynet::Client.new('bsb.hostedftp.com')
|
17
10
|
content = client.get('~auspaynetftp/BSB', filename)
|
18
11
|
hash = {}
|
19
12
|
CSV.parse(content) do |row|
|
20
|
-
row[2].split(
|
21
|
-
prefix = prefix.chomp.rjust(2,
|
13
|
+
row[2].split(', ').each do |prefix|
|
14
|
+
prefix = prefix.chomp.rjust(2, '0')
|
22
15
|
hash[prefix] = row[1]
|
23
16
|
end
|
24
17
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'auspaynet/client'
|
5
|
+
|
6
|
+
module BSB
|
7
|
+
class BaseGenerator
|
8
|
+
def initialize(hash)
|
9
|
+
@hash = hash
|
10
|
+
end
|
11
|
+
|
12
|
+
def json
|
13
|
+
JSON.dump(@hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.latest_file(matching_filename:, file_format:)
|
17
|
+
client = ::Auspaynet::Client.new('bsb.hostedftp.com')
|
18
|
+
client.list(dir: '~auspaynetftp/BSB', matching_filename: matching_filename, file_format: file_format)&.last
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,24 +1,20 @@
|
|
1
|
-
|
2
|
-
require 'auspaynet/client'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
class DatabaseGenerator
|
6
|
-
def initialize(hash)
|
7
|
-
@hash = hash
|
8
|
-
end
|
9
|
-
|
10
|
-
def json
|
11
|
-
JSON.dump(@hash)
|
12
|
-
end
|
3
|
+
require 'bsb/base_generator'
|
13
4
|
|
5
|
+
module BSB
|
6
|
+
class DatabaseGenerator < BaseGenerator
|
14
7
|
def self.load_file(filename)
|
15
8
|
client = ::Auspaynet::Client.new('bsb.hostedftp.com')
|
16
9
|
content = client.get('~auspaynetftp/BSB', filename)
|
17
10
|
hash = {}
|
18
11
|
content.each_line do |line|
|
19
|
-
next if line[3] !=
|
20
|
-
|
21
|
-
|
12
|
+
next if line[3] != '-'
|
13
|
+
|
14
|
+
bsb = line[0, 3] + line[4, 3]
|
15
|
+
hash[bsb] =
|
16
|
+
[line[7, 3], line[10, 35].strip, line[45, 35].strip, line[80, 20].strip, line[100, 3].strip, line[103, 4],
|
17
|
+
line[107, 3]]
|
22
18
|
end
|
23
19
|
new(hash)
|
24
20
|
end
|
data/lib/bsb/version.rb
CHANGED
data/lib/bsb.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bsb/version'
|
2
4
|
require 'json'
|
3
5
|
require 'bsb_number_validator'
|
@@ -8,7 +10,8 @@ module BSB
|
|
8
10
|
bsb = normalize(number)
|
9
11
|
array = data_hash[bsb]
|
10
12
|
return nil if array.nil?
|
11
|
-
|
13
|
+
|
14
|
+
{
|
12
15
|
bsb: bsb,
|
13
16
|
mnemonic: array[0],
|
14
17
|
bank_name: bank_name(bsb),
|
@@ -18,9 +21,9 @@ module BSB
|
|
18
21
|
state: array[4],
|
19
22
|
postcode: array[5],
|
20
23
|
flags: {
|
21
|
-
paper: (array[6][0] ==
|
22
|
-
electronic: (array[6][1] ==
|
23
|
-
high_value: (array[6][2] ==
|
24
|
+
paper: (array[6][0] == 'P'),
|
25
|
+
electronic: (array[6][1] == 'E'),
|
26
|
+
high_value: (array[6][2] == 'H')
|
24
27
|
}
|
25
28
|
}
|
26
29
|
end
|
@@ -29,20 +32,21 @@ module BSB
|
|
29
32
|
bank_list.each do |prefix, bank_name|
|
30
33
|
return bank_name if bsb.start_with? prefix
|
31
34
|
end
|
32
|
-
|
35
|
+
nil
|
33
36
|
end
|
34
37
|
|
35
38
|
def normalize(str)
|
36
39
|
str.gsub(/[^\d]/, '')
|
37
40
|
end
|
38
41
|
|
39
|
-
|
42
|
+
protected
|
43
|
+
|
40
44
|
def data_hash
|
41
|
-
@data_hash ||= JSON.parse(
|
45
|
+
@data_hash ||= JSON.parse(File.read(File.expand_path('../config/bsb_db.json', __dir__)))
|
42
46
|
end
|
43
47
|
|
44
48
|
def bank_list
|
45
|
-
@bank_list ||= JSON.parse(
|
49
|
+
@bank_list ||= JSON.parse(File.read(File.expand_path('../config/bsb_bank_list.json', __dir__)))
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
data/lib/bsb_number_validator.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'active_model'
|
3
4
|
|
4
5
|
class BsbNumberValidator < ActiveModel::EachValidator
|
5
6
|
def validate_each(record, attribute, value)
|
6
|
-
unless BSB.lookup(value)
|
7
|
-
record.errors.add(attribute, :invalid)
|
8
|
-
end
|
7
|
+
record.errors.add(attribute, :invalid) unless BSB.lookup(value)
|
9
8
|
end
|
10
9
|
end
|
data/lib/tasks/bsb_tasks.rake
CHANGED
@@ -1,25 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :bsb do
|
2
|
-
desc
|
3
|
-
task :
|
4
|
-
require 'bsb/
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
desc 'Sync config/*.json.'
|
5
|
+
task :sync do
|
6
|
+
require 'bsb/base_generator'
|
7
|
+
bank_list_filename = BSB::BaseGenerator.latest_file(
|
8
|
+
matching_filename: 'KEY TO ABBREVIATIONS AND BSB NUMBERS',
|
9
|
+
file_format: '.csv'
|
10
|
+
)
|
11
|
+
db_list_filename = BSB::BaseGenerator.latest_file(
|
12
|
+
matching_filename: 'BSBDirectory',
|
13
|
+
file_format: '.txt'
|
14
|
+
)
|
13
15
|
|
14
|
-
desc "Generate JSON-formatted bank list from APCA BSB directory"
|
15
|
-
task :generate_bank_list do
|
16
16
|
require 'bsb/bank_list_generator'
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
17
|
+
bsb_bl_gen = BSB::BankListGenerator.load_file(bank_list_filename)
|
18
|
+
File.write('config/bsb_bank_list.json', bsb_bl_gen.json)
|
19
|
+
|
20
|
+
require 'bsb/database_generator'
|
21
|
+
bsb_db_gen = BSB::DatabaseGenerator.load_file(db_list_filename)
|
22
|
+
File.write('config/bsb_db.json', bsb_db_gen.json)
|
24
23
|
end
|
25
24
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe BsbNumberValidator do
|
6
|
+
it '#valid?' do
|
7
|
+
assert_equal true, Account.new(bsb: '092009', account_number: '218963243', account_name: 'Bruce Wayne').valid?
|
8
|
+
assert_equal false, Account.new(bsb: '000001', account_number: '218963243', account_name: 'Bruce Wayne').valid?
|
9
|
+
end
|
10
|
+
end
|
data/test/bsb_test.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe BSB do
|
6
|
+
it '.lookup' do
|
7
|
+
details = {
|
8
|
+
bsb: '092009', mnemonic: 'RBA', bank_name: 'Reserve Bank of Australia',
|
9
|
+
branch: 'Canberra', address: '20-22 London Circuit', suburb: 'Canberra',
|
10
|
+
state: 'ACT', postcode: '2601', flags: { paper: true, electronic: true,
|
11
|
+
high_value: true }
|
12
|
+
}
|
13
|
+
|
14
|
+
assert_equal details, BSB.lookup('092009')
|
15
|
+
end
|
16
|
+
|
17
|
+
it '.bank_name' do
|
18
|
+
assert_equal 'Reserve Bank of Australia', BSB.bank_name('092009')
|
19
|
+
end
|
20
|
+
|
21
|
+
it '.normalize special char' do
|
22
|
+
assert_equal '083004', BSB.normalize('083-004')
|
23
|
+
end
|
24
|
+
|
25
|
+
it '.normalize whitespace' do
|
26
|
+
assert_equal '062000', BSB.normalize('06 2000')
|
27
|
+
end
|
28
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bsb'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
class Account
|
7
|
+
include ActiveModel::API
|
8
|
+
|
9
|
+
attr_accessor :bsb, :account_number, :account_name
|
10
|
+
|
11
|
+
validates :bsb, :account_number, :account_name, presence: true
|
12
|
+
validates :bsb, length: { is: 6 }, bsb_number: true
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bsb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Zhou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-ftp
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.3
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.26'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.26'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: activemodel
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,10 +87,15 @@ executables: []
|
|
59
87
|
extensions: []
|
60
88
|
extra_rdoc_files: []
|
61
89
|
files:
|
62
|
-
- ".github/workflows/
|
90
|
+
- ".github/workflows/ci.yml"
|
91
|
+
- ".github/workflows/release.yml"
|
92
|
+
- ".github/workflows/update-database.yml"
|
63
93
|
- ".gitignore"
|
94
|
+
- ".release-please-manifest.json"
|
95
|
+
- ".rubocop.yml"
|
96
|
+
- ".ruby-version"
|
97
|
+
- CHANGELOG.md
|
64
98
|
- Gemfile
|
65
|
-
- Gemfile.lock
|
66
99
|
- LICENSE.txt
|
67
100
|
- README.md
|
68
101
|
- Rakefile
|
@@ -72,14 +105,19 @@ files:
|
|
72
105
|
- lib/auspaynet/client.rb
|
73
106
|
- lib/bsb.rb
|
74
107
|
- lib/bsb/bank_list_generator.rb
|
108
|
+
- lib/bsb/base_generator.rb
|
75
109
|
- lib/bsb/database_generator.rb
|
76
110
|
- lib/bsb/version.rb
|
77
111
|
- lib/bsb_number_validator.rb
|
78
112
|
- lib/tasks/bsb_tasks.rake
|
113
|
+
- test/bsb_number_validator_test.rb
|
114
|
+
- test/bsb_test.rb
|
115
|
+
- test/test_helper.rb
|
79
116
|
homepage: https://github.com/zhoutong/bsb
|
80
117
|
licenses:
|
81
118
|
- MIT
|
82
|
-
metadata:
|
119
|
+
metadata:
|
120
|
+
rubygems_mfa_required: 'false'
|
83
121
|
post_install_message:
|
84
122
|
rdoc_options: []
|
85
123
|
require_paths:
|
@@ -88,14 +126,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
126
|
requirements:
|
89
127
|
- - ">="
|
90
128
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
129
|
+
version: 2.7.0
|
92
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
131
|
requirements:
|
94
132
|
- - ">="
|
95
133
|
- !ruby/object:Gem::Version
|
96
134
|
version: '0'
|
97
135
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
136
|
+
rubygems_version: 3.3.7
|
99
137
|
signing_key:
|
100
138
|
specification_version: 4
|
101
139
|
summary: BSB number validator with built-in database.
|
@@ -1,45 +0,0 @@
|
|
1
|
-
name: Ruby Gem
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [ master ]
|
6
|
-
pull_request:
|
7
|
-
branches: [ master ]
|
8
|
-
|
9
|
-
jobs:
|
10
|
-
build:
|
11
|
-
name: Build + Publish
|
12
|
-
runs-on: ubuntu-latest
|
13
|
-
permissions:
|
14
|
-
contents: read
|
15
|
-
packages: write
|
16
|
-
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v3
|
19
|
-
- name: Set up Ruby 2.6
|
20
|
-
uses: actions/setup-ruby@v1
|
21
|
-
with:
|
22
|
-
ruby-version: 2.6.x
|
23
|
-
|
24
|
-
- name: Publish to GPR
|
25
|
-
run: |
|
26
|
-
mkdir -p $HOME/.gem
|
27
|
-
touch $HOME/.gem/credentials
|
28
|
-
chmod 0600 $HOME/.gem/credentials
|
29
|
-
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
30
|
-
gem build *.gemspec
|
31
|
-
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
32
|
-
env:
|
33
|
-
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
34
|
-
OWNER: ${{ github.repository_owner }}
|
35
|
-
|
36
|
-
- name: Publish to RubyGems
|
37
|
-
run: |
|
38
|
-
mkdir -p $HOME/.gem
|
39
|
-
touch $HOME/.gem/credentials
|
40
|
-
chmod 0600 $HOME/.gem/credentials
|
41
|
-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
42
|
-
gem build *.gemspec
|
43
|
-
gem push *.gem
|
44
|
-
env:
|
45
|
-
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
|
data/Gemfile.lock
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
bsb (0.0.15)
|
5
|
-
activemodel
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activemodel (6.1.6)
|
11
|
-
activesupport (= 6.1.6)
|
12
|
-
activesupport (6.1.6)
|
13
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>= 1.6, < 2)
|
15
|
-
minitest (>= 5.1)
|
16
|
-
tzinfo (~> 2.0)
|
17
|
-
zeitwerk (~> 2.3)
|
18
|
-
concurrent-ruby (1.1.10)
|
19
|
-
i18n (1.10.0)
|
20
|
-
concurrent-ruby (~> 1.0)
|
21
|
-
minitest (5.15.0)
|
22
|
-
rake (13.0.1)
|
23
|
-
tzinfo (2.0.4)
|
24
|
-
concurrent-ruby (~> 1.0)
|
25
|
-
zeitwerk (2.5.4)
|
26
|
-
|
27
|
-
PLATFORMS
|
28
|
-
ruby
|
29
|
-
|
30
|
-
DEPENDENCIES
|
31
|
-
bsb!
|
32
|
-
bundler (~> 2.0)
|
33
|
-
rake (~> 13.0)
|
34
|
-
|
35
|
-
BUNDLED WITH
|
36
|
-
2.3.7
|