bsb 0.0.16 → 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.
@@ -4,7 +4,7 @@ require 'net/ftp'
4
4
 
5
5
  module Auspaynet
6
6
  class Client
7
- MONTHS = %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
7
+ MONTHS = %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec].freeze
8
8
 
9
9
  def initialize(host)
10
10
  @host = host
@@ -24,10 +24,11 @@ module Auspaynet
24
24
  @ftp.chdir(dir)
25
25
  files = @ftp.nlst.select do |f|
26
26
  f.include?(matching_filename) &&
27
- f.include?(file_format) &&
28
- f.include?(current_year)
27
+ f.include?(file_format) &&
28
+ f.include?(current_year)
29
29
  end
30
- extract_latest_files(files:, matching_filename:, file_format:)
30
+
31
+ extract_latest_files(files: files, file_format: file_format)
31
32
  ensure
32
33
  @ftp.chdir('/')
33
34
  end
@@ -35,15 +36,17 @@ module Auspaynet
35
36
  private
36
37
 
37
38
  def current_year
38
- Time.now.strftime("%y")
39
+ Time.now.strftime('%y')
39
40
  end
40
41
 
41
- def extract_latest_files(files:, matching_filename:, file_format:)
42
- files.sort_by { |filename| file_for_month(filename:, matching_filename:, file_format:) }
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
43
46
  end
44
47
 
45
- def file_for_month(filename:, matching_filename:, file_format:)
46
- month_from_filename = filename.gsub(/(#{filename}|\#{file_format}|\W|\d)/,'')
48
+ def file_for_month(filename:, file_format:)
49
+ month_from_filename = filename.gsub(/(#{filename}|#{file_format}|\W|\d)/, '')
47
50
  month_number(month_from_filename)
48
51
  end
49
52
 
@@ -15,7 +15,7 @@ module BSB
15
15
 
16
16
  def self.latest_file(matching_filename:, file_format:)
17
17
  client = ::Auspaynet::Client.new('bsb.hostedftp.com')
18
- client.list(dir: '~auspaynetftp/BSB', matching_filename:, file_format:)&.last
18
+ client.list(dir: '~auspaynetftp/BSB', matching_filename: matching_filename, file_format: file_format)&.last
19
19
  end
20
20
  end
21
21
  end
data/lib/bsb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BSB
4
- VERSION = '0.0.16'
4
+ VERSION = '1.0.0'.freeze
5
5
  end
data/lib/bsb.rb CHANGED
@@ -39,14 +39,14 @@ module BSB
39
39
  str.gsub(/[^\d]/, '')
40
40
  end
41
41
 
42
- private
42
+ protected
43
43
 
44
44
  def data_hash
45
- @data_hash ||= JSON.parse(IO.read(File.expand_path('../config/bsb_db.json', __dir__)))
45
+ @data_hash ||= JSON.parse(File.read(File.expand_path('../config/bsb_db.json', __dir__)))
46
46
  end
47
47
 
48
48
  def bank_list
49
- @bank_list ||= JSON.parse(IO.read(File.expand_path('../config/bsb_bank_list.json', __dir__)))
49
+ @bank_list ||= JSON.parse(File.read(File.expand_path('../config/bsb_bank_list.json', __dir__)))
50
50
  end
51
51
  end
52
52
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bsb'
4
3
  require 'active_model'
5
4
 
6
5
  class BsbNumberValidator < ActiveModel::EachValidator
@@ -1,31 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :bsb do
4
- desc 'Generate JSON-formatted database from APCA BSB directory'
5
- task :generate_database do
6
- require 'bsb/database_generator'
7
- if filename = ENV['filename']
8
- warn 'Loading BSB file from APCA FTP server... (This may take a while)'
9
- bsb_db_gen = BSB::DatabaseGenerator.load_file(filename)
10
- puts bsb_db_gen.json
11
- else
12
- warn 'Filename variable must be passed. For example, `rake bsb:generate_database filename=BSBDirectoryMay22-314.txt > config/bsb_db.json`'
13
- end
14
- end
15
-
16
- desc 'Generate JSON-formatted bank list from APCA BSB directory'
17
- task :generate_bank_list do
18
- require 'bsb/bank_list_generator'
19
- if filename = ENV['filename']
20
- warn 'Loading Bank List file... (This may take a while)'
21
- bsb_bl_gen = BSB::BankListGenerator.load_file(filename)
22
- puts bsb_bl_gen.json
23
- else
24
- warn "URL variable must be passed. For example, `rake bsb:generate_bank_list filename='KEY TO ABBREVIATIONS AND BSB NUMBERS (May 2022).csv' > config/bsb_bank_list.json`"
25
- end
26
- end
27
-
28
- desc 'Sync database and bank list'
4
+ desc 'Sync config/*.json.'
29
5
  task :sync do
30
6
  require 'bsb/base_generator'
31
7
  bank_list_filename = BSB::BaseGenerator.latest_file(
@@ -37,7 +13,12 @@ namespace :bsb do
37
13
  file_format: '.txt'
38
14
  )
39
15
 
40
- system "rake bsb:generate_bank_list filename='#{bank_list_filename}' > config/bsb_bank_list.json"
41
- system "rake bsb:generate_database filename='#{db_list_filename}' > config/bsb_db.json"
16
+ require 'bsb/bank_list_generator'
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)
42
23
  end
43
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
@@ -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.16
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-07-01 00:00:00.000000000 Z
11
+ date: 2022-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
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'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: activemodel
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -73,11 +87,15 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
- - ".github/workflows/gem-push.yml"
77
- - ".github/workflows/sync-bank-details.yml"
90
+ - ".github/workflows/ci.yml"
91
+ - ".github/workflows/release.yml"
92
+ - ".github/workflows/update-database.yml"
78
93
  - ".gitignore"
94
+ - ".release-please-manifest.json"
95
+ - ".rubocop.yml"
96
+ - ".ruby-version"
97
+ - CHANGELOG.md
79
98
  - Gemfile
80
- - Gemfile.lock
81
99
  - LICENSE.txt
82
100
  - README.md
83
101
  - Rakefile
@@ -92,10 +110,14 @@ files:
92
110
  - lib/bsb/version.rb
93
111
  - lib/bsb_number_validator.rb
94
112
  - lib/tasks/bsb_tasks.rake
113
+ - test/bsb_number_validator_test.rb
114
+ - test/bsb_test.rb
115
+ - test/test_helper.rb
95
116
  homepage: https://github.com/zhoutong/bsb
96
117
  licenses:
97
118
  - MIT
98
- metadata: {}
119
+ metadata:
120
+ rubygems_mfa_required: 'false'
99
121
  post_install_message:
100
122
  rdoc_options: []
101
123
  require_paths:
@@ -104,14 +126,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
126
  requirements:
105
127
  - - ">="
106
128
  - !ruby/object:Gem::Version
107
- version: '0'
129
+ version: 2.7.0
108
130
  required_rubygems_version: !ruby/object:Gem::Requirement
109
131
  requirements:
110
132
  - - ">="
111
133
  - !ruby/object:Gem::Version
112
134
  version: '0'
113
135
  requirements: []
114
- rubygems_version: 3.0.3.1
136
+ rubygems_version: 3.3.7
115
137
  signing_key:
116
138
  specification_version: 4
117
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}}"
@@ -1,24 +0,0 @@
1
- name: Sync Bank List and Database
2
-
3
- on:
4
- schedule:
5
- - cron: "0 0 1 * *"
6
-
7
- jobs:
8
- build:
9
- name: Build + Sync
10
- runs-on: ubuntu-latest
11
- steps:
12
- - uses: actions/checkout@v3
13
- - name: Set up Ruby 2.6
14
- uses: actions/setup-ruby@v1
15
- with:
16
- ruby-version: 2.6.x
17
- - name: Sync gem
18
- run: |
19
- bundle exec rake bsb:sync
20
- git config user.name github-actions
21
- git config user.email github-actions@github.com
22
- git add .
23
- git commit -m "fix: Sync update on ${date}"
24
- git push
data/Gemfile.lock DELETED
@@ -1,44 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- bsb (0.0.16)
5
- activemodel
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (7.0.3)
11
- activesupport (= 7.0.3)
12
- activesupport (7.0.3)
13
- concurrent-ruby (~> 1.0, >= 1.0.2)
14
- i18n (>= 1.6, < 2)
15
- minitest (>= 5.1)
16
- tzinfo (~> 2.0)
17
- concurrent-ruby (1.1.10)
18
- date (3.2.2)
19
- i18n (1.10.0)
20
- concurrent-ruby (~> 1.0)
21
- minitest (5.16.0)
22
- net-ftp (0.1.3)
23
- net-protocol
24
- time
25
- net-protocol (0.1.3)
26
- timeout
27
- rake (13.0.1)
28
- time (0.2.0)
29
- date
30
- timeout (0.3.0)
31
- tzinfo (2.0.4)
32
- concurrent-ruby (~> 1.0)
33
-
34
- PLATFORMS
35
- ruby
36
-
37
- DEPENDENCIES
38
- bsb!
39
- bundler (~> 2.0)
40
- net-ftp (~> 0.1.3)
41
- rake (~> 13.0)
42
-
43
- BUNDLED WITH
44
- 2.3.7