simple_form-bank_account_number 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +19 -0
- data/Rakefile +8 -0
- data/lib/simple_form/bank_account_number.rb +68 -0
- data/lib/simple_form/bank_account_number/countries.rb +29 -0
- data/lib/simple_form/bank_account_number/version.rb +5 -0
- data/simple_form-bank_account_number.gemspec +25 -0
- data/spec/simple_form/bank_account_number_spec.rb +62 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2188cdec0054eac3d21d6f8a3140a0f9583dc13f
|
4
|
+
data.tar.gz: fbfcc9ff25ecda050792cf5e484b14fd2cda5738
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e3eb8e1be8822635d0b19754ff813e5e3dd00d3344d389d460dfa8ede534b76b57ff82cf0977e5f79741c45d19cdc7dc30b444f753a798082746266cb19873d6
|
7
|
+
data.tar.gz: 088c58a15718874b6f7c72c22d5348e21ab6557a62d25cd867dd6403c4d07ac8a9120e9483f76d1405b04aab76e05175fb3561be9d91f5d2d4d89e3cc38b6c04
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bucky Box Limited
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# SimpleForm::BankAccountNumber
|
2
|
+
|
3
|
+
A [SimpleForm](https://github.com/plataformatec/simple_form) input field for bank account numbers.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Just create a new input field with `:bank_account_number` as its type.
|
8
|
+
Note that you need to explicitly set the `country` and `value` options, like this:
|
9
|
+
|
10
|
+
`f.input_field :account_number, as: :bank_account_number, country: user.country, value: user.account_number`
|
11
|
+
|
12
|
+
- the country is the [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) representation
|
13
|
+
- the value can't be inferred automatically unfortunately so you have to set it explicitly
|
14
|
+
|
15
|
+
Also note that you'll get multiple values for each number part upon form submission.
|
16
|
+
You probably want to concatenate them into one single number for your backend with something along these lines:
|
17
|
+
|
18
|
+
`params[:bank_deposit][:account_number] = params[:bank_deposit][:account_number].join`
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "simple_form"
|
2
|
+
require "simple_form/bank_account_number/countries"
|
3
|
+
require "simple_form/bank_account_number/version"
|
4
|
+
|
5
|
+
module SimpleForm
|
6
|
+
module Inputs
|
7
|
+
class BankAccountNumberInput < NumericInput
|
8
|
+
def self.formatted_bank_account_number(full_number, country)
|
9
|
+
full_number = full_number.dup
|
10
|
+
|
11
|
+
fields = number_format(country).map do |part|
|
12
|
+
length = part[:format].source.scan(/\b\d}/).map(&:to_i).max
|
13
|
+
full_number.slice!(0, length || full_number.length)
|
14
|
+
end
|
15
|
+
|
16
|
+
unless full_number.empty?
|
17
|
+
raise ArgumentError, "format does not match (#{full_number.length} extra digits)"
|
18
|
+
end
|
19
|
+
|
20
|
+
fields.join("-")
|
21
|
+
end
|
22
|
+
|
23
|
+
# requires to set :country and :value
|
24
|
+
def input
|
25
|
+
country = options.delete(:country) || raise(ArgumentError, "You must set the :country key.")
|
26
|
+
full_number = options.fetch(:value) || ""
|
27
|
+
parts = self.class.formatted_bank_account_number(full_number, country).split("-").reverse
|
28
|
+
|
29
|
+
fields = self.class.number_format(country).map do |part|
|
30
|
+
input_html_options[:required] = "required"
|
31
|
+
input_html_options[:autocomplete] = "off"
|
32
|
+
input_html_options[:name] = "#{lookup_model_names.join("_")}[#{reflection_or_attribute_name}][]"
|
33
|
+
input_html_options[:pattern] = "^#{part[:format].source}$"
|
34
|
+
input_html_options[:title] = part[:label]
|
35
|
+
input_html_options[:style] = "width: auto; display: inline; margin-right: .2em"
|
36
|
+
input_html_options.delete(:country) # don't include it in the markup
|
37
|
+
|
38
|
+
# Twitter Bootstrap tooltips
|
39
|
+
input_html_options["data-toggle"] = "tooltip"
|
40
|
+
input_html_options["data-original-title"] = part[:label]
|
41
|
+
input_html_options["data-placement"] = "bottom"
|
42
|
+
|
43
|
+
if length = part[:format].source.scan(/\b\d}/).map(&:to_i).max
|
44
|
+
input_html_options[:size] = length
|
45
|
+
input_html_options[:maxlength] = length
|
46
|
+
else
|
47
|
+
input_html_options[:size] = nil
|
48
|
+
input_html_options[:maxlength] = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
input_html_options[:value] = parts.pop
|
52
|
+
|
53
|
+
super
|
54
|
+
end
|
55
|
+
|
56
|
+
fields.join
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def self.number_format(country)
|
62
|
+
SimpleForm::BankAccountNumber::COUNTRIES[country.upcase] ||
|
63
|
+
SimpleForm::BankAccountNumber::DEFAULT_FORMAT
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SimpleForm
|
2
|
+
module BankAccountNumber
|
3
|
+
COUNTRIES = {
|
4
|
+
"AU" => [
|
5
|
+
{ label: "6 digit BSB number", format: /\d{6}/ },
|
6
|
+
{ label: "6 to 9 digit account number", format: /\d{6,9}/ },
|
7
|
+
],
|
8
|
+
"CA" => [
|
9
|
+
{ label: "8 or 9 digit transit number", format: /\d{8,9}/ },
|
10
|
+
{ label: "7 to 12 digit account number", format: /\d{7,12}/ },
|
11
|
+
],
|
12
|
+
"GB" => [
|
13
|
+
{ label: "6 digit sort code", format: /\d{6}/ },
|
14
|
+
{ label: "7 to 10 digit account number", format: /\d{7,10}/ },
|
15
|
+
],
|
16
|
+
"NZ" => [
|
17
|
+
{ label: "2 digit bank number", format: /\d{2}/ },
|
18
|
+
{ label: "4 digit branch number", format: /\d{4}/ },
|
19
|
+
{ label: "7 digit account number", format: /\d{7}/ },
|
20
|
+
{ label: "2 or 3 digit suffix", format: /\d{2,3}/ },
|
21
|
+
],
|
22
|
+
}
|
23
|
+
|
24
|
+
DEFAULT_FORMAT = [
|
25
|
+
{ label: "account number", format: /[A-Z0-9]+/ }
|
26
|
+
]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_form/bank_account_number/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_form-bank_account_number"
|
8
|
+
spec.version = SimpleForm::BankAccountNumber::VERSION
|
9
|
+
spec.authors = ["Cédric Félizard"]
|
10
|
+
spec.email = ["cedric@felizard.fr"]
|
11
|
+
spec.description = %q{A SimpleForm input field for bank account numbers}
|
12
|
+
spec.summary = %q{Bank account number field for SimpleForm}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "simple_form", "~> 2.1.0"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "simple_form/bank_account_number"
|
2
|
+
|
3
|
+
class CustomFormBuilder < SimpleForm::FormBuilder
|
4
|
+
class << self
|
5
|
+
def object
|
6
|
+
"custom_object"
|
7
|
+
end
|
8
|
+
|
9
|
+
def lookup_model_names
|
10
|
+
%w(model_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def text_field(*)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module SimpleForm::Inputs
|
19
|
+
describe BankAccountNumberInput do
|
20
|
+
describe ".formatted_bank_account_number" do
|
21
|
+
def assert country, number, formatted_number
|
22
|
+
expect(BankAccountNumberInput.formatted_bank_account_number(number, country)).to eq formatted_number
|
23
|
+
end
|
24
|
+
|
25
|
+
specify do
|
26
|
+
assert "AU", "484795453513423", "484795-453513423"
|
27
|
+
assert "GB", "40142431565517", "401424-31565517"
|
28
|
+
assert "NZ", "041587005000000", "04-1587-0050000-00"
|
29
|
+
assert "XX", "1234", "1234"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "preserves the given number" do
|
33
|
+
number = "484795453513423"
|
34
|
+
BankAccountNumberInput.formatted_bank_account_number(number, "AU")
|
35
|
+
|
36
|
+
expect(number).to eq "484795453513423"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#input" do
|
41
|
+
let(:options) do
|
42
|
+
{
|
43
|
+
country: "NZ",
|
44
|
+
value: "041587005000000",
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
it "generates the input field successfully" do
|
49
|
+
input = BankAccountNumberInput.new(
|
50
|
+
CustomFormBuilder, # builder class
|
51
|
+
"test_attribute", # attribute_name
|
52
|
+
"test_column", # column
|
53
|
+
"bank_account_number", # input_type
|
54
|
+
options
|
55
|
+
)
|
56
|
+
|
57
|
+
expect { input.input }.not_to raise_error
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_form-bank_account_number
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cédric Félizard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: simple_form
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '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: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A SimpleForm input field for bank account numbers
|
70
|
+
email:
|
71
|
+
- cedric@felizard.fr
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/simple_form/bank_account_number.rb
|
83
|
+
- lib/simple_form/bank_account_number/countries.rb
|
84
|
+
- lib/simple_form/bank_account_number/version.rb
|
85
|
+
- simple_form-bank_account_number.gemspec
|
86
|
+
- spec/simple_form/bank_account_number_spec.rb
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Bank account number field for SimpleForm
|
111
|
+
test_files:
|
112
|
+
- spec/simple_form/bank_account_number_spec.rb
|