swiss_bank_validator 0.5.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 +7 -0
- data/.github/workflows/ruby.yml +30 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +14 -0
- data/bin/console +16 -0
- data/bin/setup +8 -0
- data/changelog.md +0 -0
- data/lib/swiss_bank_validator.rb +9 -0
- data/lib/swiss_bank_validator/constants.rb +6 -0
- data/lib/swiss_bank_validator/locale/de.yml +11 -0
- data/lib/swiss_bank_validator/locale/en.yml +11 -0
- data/lib/swiss_bank_validator/locale/fr.yml +11 -0
- data/lib/swiss_bank_validator/validates_iban_format_of.rb +104 -0
- data/lib/swiss_bank_validator/version.rb +5 -0
- data/swiss_bank_validator.gemspec +34 -0
- metadata +109 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3d7762e4e03b89969464a21bce678f3e1baade2f8c6ac10699053df10c2e85c7
|
|
4
|
+
data.tar.gz: 813db18abed54ecc1bd9539bf153f4f9e892adb4b7b4bd0bc1e2f1fd986d60cd
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4ba3584616147db8d03d2c8ec32dce06d132d2c6588cd70c365e4af22825eb90c4fbf54b74c41567ba580e66135112f1a90c69d845da795d3c4211225174c61a
|
|
7
|
+
data.tar.gz: '0139dd4488250ff2f3d52b5cc9e92687c09cc46c532098c84805a57ba6da2b28f73f5cc103fcd528ac81fa20c0f9f2ae33cecbf9f6f47bf1beb7abb2b737de0d'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: Ruby
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ main ]
|
|
13
|
+
pull_request:
|
|
14
|
+
branches: [ main ]
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
test:
|
|
18
|
+
|
|
19
|
+
runs-on: ubuntu-20.04
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v2
|
|
23
|
+
- name: Set up Ruby
|
|
24
|
+
uses: ruby/setup-ruby@v1
|
|
25
|
+
with:
|
|
26
|
+
ruby-version: 2.7.2
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: bundle install
|
|
29
|
+
- name: Run tests & Rubocop
|
|
30
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at jbiolaz@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
swiss_bank_validator (0.5.0)
|
|
5
|
+
activemodel (~> 6.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activemodel (6.0.3.4)
|
|
11
|
+
activesupport (= 6.0.3.4)
|
|
12
|
+
activesupport (6.0.3.4)
|
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
14
|
+
i18n (>= 0.7, < 2)
|
|
15
|
+
minitest (~> 5.1)
|
|
16
|
+
tzinfo (~> 1.1)
|
|
17
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
18
|
+
ast (2.4.1)
|
|
19
|
+
concurrent-ruby (1.1.7)
|
|
20
|
+
diff-lcs (1.4.4)
|
|
21
|
+
i18n (1.8.5)
|
|
22
|
+
concurrent-ruby (~> 1.0)
|
|
23
|
+
minitest (5.14.2)
|
|
24
|
+
parallel (1.20.1)
|
|
25
|
+
parser (2.7.2.0)
|
|
26
|
+
ast (~> 2.4.1)
|
|
27
|
+
rainbow (3.0.0)
|
|
28
|
+
rake (12.3.3)
|
|
29
|
+
regexp_parser (2.0.0)
|
|
30
|
+
rexml (3.2.4)
|
|
31
|
+
rspec (3.10.0)
|
|
32
|
+
rspec-core (~> 3.10.0)
|
|
33
|
+
rspec-expectations (~> 3.10.0)
|
|
34
|
+
rspec-mocks (~> 3.10.0)
|
|
35
|
+
rspec-core (3.10.0)
|
|
36
|
+
rspec-support (~> 3.10.0)
|
|
37
|
+
rspec-expectations (3.10.0)
|
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
39
|
+
rspec-support (~> 3.10.0)
|
|
40
|
+
rspec-mocks (3.10.0)
|
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
42
|
+
rspec-support (~> 3.10.0)
|
|
43
|
+
rspec-support (3.10.0)
|
|
44
|
+
rubocop (1.5.0)
|
|
45
|
+
parallel (~> 1.10)
|
|
46
|
+
parser (>= 2.7.1.5)
|
|
47
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
48
|
+
regexp_parser (>= 2.0)
|
|
49
|
+
rexml
|
|
50
|
+
rubocop-ast (>= 1.2.0)
|
|
51
|
+
ruby-progressbar (~> 1.7)
|
|
52
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
53
|
+
rubocop-ast (1.3.0)
|
|
54
|
+
parser (>= 2.7.1.5)
|
|
55
|
+
ruby-progressbar (1.10.1)
|
|
56
|
+
thread_safe (0.3.6)
|
|
57
|
+
tzinfo (1.2.8)
|
|
58
|
+
thread_safe (~> 0.1)
|
|
59
|
+
unicode-display_width (1.7.0)
|
|
60
|
+
zeitwerk (2.4.2)
|
|
61
|
+
|
|
62
|
+
PLATFORMS
|
|
63
|
+
ruby
|
|
64
|
+
|
|
65
|
+
DEPENDENCIES
|
|
66
|
+
rake (~> 12.0)
|
|
67
|
+
rspec (~> 3.0)
|
|
68
|
+
rubocop (~> 1.5)
|
|
69
|
+
swiss_bank_validator!
|
|
70
|
+
|
|
71
|
+
BUNDLED WITH
|
|
72
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Jonathan Biolaz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# SwissBankValidator
|
|
2
|
+
|
|
3
|
+
Allow to valid a Swiss Iban passed on the rules of http://www.swissiban.com/
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'swiss_bank_validator'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle install
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install swiss_bank_validator
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
class Account < ActiveRecord::Base
|
|
25
|
+
validates_iban_format_of :account_number
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# or
|
|
29
|
+
|
|
30
|
+
class Account < ActiveRecord::Base
|
|
31
|
+
validates :account_number, iban: true
|
|
32
|
+
end
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Development
|
|
36
|
+
|
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
38
|
+
|
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
40
|
+
|
|
41
|
+
## Contributing
|
|
42
|
+
|
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/iban_validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/iban_validator/blob/master/CODE_OF_CONDUCT.md).
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
49
|
+
|
|
50
|
+
## Code of Conduct
|
|
51
|
+
|
|
52
|
+
Everyone interacting in the SwissBankValidator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/iban_validator/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rubocop/rake_task'
|
|
5
|
+
require 'rspec/core/rake_task'
|
|
6
|
+
|
|
7
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
|
8
|
+
t.options << '--config'
|
|
9
|
+
t.options << File.expand_path('.rubocop.yml', __dir__)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
13
|
+
|
|
14
|
+
task default: %i[spec rubocop]
|
data/bin/console
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
#!/usr/bin/env ruby
|
|
4
|
+
|
|
5
|
+
require 'bundler/setup'
|
|
6
|
+
require 'iban_validator'
|
|
7
|
+
|
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
10
|
+
|
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
12
|
+
# require "pry"
|
|
13
|
+
# Pry.start
|
|
14
|
+
|
|
15
|
+
require 'irb'
|
|
16
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/changelog.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SwissBankValidator
|
|
4
|
+
require 'swiss_bank_validator/version'
|
|
5
|
+
require 'swiss_bank_validator/constants'
|
|
6
|
+
require 'swiss_bank_validator/validates_iban_format_of'
|
|
7
|
+
|
|
8
|
+
I18n.load_path += Dir[File.join(__dir__, 'swiss_bank_validator/locale/*.yml')]
|
|
9
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
de:
|
|
2
|
+
activemodel: &activemodel
|
|
3
|
+
errors:
|
|
4
|
+
messages:
|
|
5
|
+
invalid_iban_length: "Überprüfe bitte die Länge der angegebenen IBAN. Sie muss %{value} Charakter lang sein."
|
|
6
|
+
space_not_authorized_in_iban: Abstände sind nicht zugelassen.
|
|
7
|
+
iban_format_not_valid: Das Format der angegebenen IBAN ist nicht gültig.
|
|
8
|
+
must_start_with_ch: "Beginnt mit CH"
|
|
9
|
+
|
|
10
|
+
activerecord:
|
|
11
|
+
<<: *activemodel
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
en:
|
|
2
|
+
activemodel: &activemodel
|
|
3
|
+
errors:
|
|
4
|
+
messages:
|
|
5
|
+
invalid_iban_length: "IBAN length is not valid. must be %{value}"
|
|
6
|
+
space_not_authorized_in_iban: "Spaces are not authorized"
|
|
7
|
+
iban_format_not_valid: "Your IBAN format is not valid"
|
|
8
|
+
must_start_with_ch: "Must start with CH"
|
|
9
|
+
|
|
10
|
+
activerecord:
|
|
11
|
+
<<: *activemodel
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
fr:
|
|
2
|
+
activemodel: &activemodel
|
|
3
|
+
errors:
|
|
4
|
+
messages:
|
|
5
|
+
invalid_iban_length: "La longueur de l'IBAN n'est pas correct. Il doit être de %{value}"
|
|
6
|
+
space_not_authorized_in_iban: "Les espaces ne sont pas autorisés"
|
|
7
|
+
iban_format_not_valid: "Le format de l'IBAN n'est pas valide"
|
|
8
|
+
must_start_with_ch: "doit commencer par CH"
|
|
9
|
+
|
|
10
|
+
activerecord:
|
|
11
|
+
<<: *activemodel
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Based on http://www.swissiban.com/fr.htm
|
|
4
|
+
module ActiveModel
|
|
5
|
+
module Validations
|
|
6
|
+
class IbanValidator < EachValidator
|
|
7
|
+
def validate_each(record, attribute, value)
|
|
8
|
+
return if value.blank? && options[:allow_blank]
|
|
9
|
+
return if value.nil? && options[:allow_nil]
|
|
10
|
+
|
|
11
|
+
return unless validate_iban_length(record, attribute, value, options)
|
|
12
|
+
|
|
13
|
+
validate_start_with_ch(record, attribute, value, options)
|
|
14
|
+
validate_iban_with_regex(record, attribute, value, options)
|
|
15
|
+
validate_iban_format(record, attribute, value, options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def validate_iban_length(record, attribute, value, options)
|
|
19
|
+
return true if value.length == SwissBankValidator::IBAN_LENGTH
|
|
20
|
+
|
|
21
|
+
record.errors.add(
|
|
22
|
+
attribute,
|
|
23
|
+
:invalid_iban_length,
|
|
24
|
+
message: options[:message],
|
|
25
|
+
value: SwissBankValidator::IBAN_LENGTH
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
false
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def validate_iban_with_regex(record, attribute, value, options)
|
|
32
|
+
return if SwissBankValidator::IBAN_REGEX.match(value).present?
|
|
33
|
+
|
|
34
|
+
record.errors.add(
|
|
35
|
+
attribute,
|
|
36
|
+
:space_not_authorized_in_iban,
|
|
37
|
+
message: options[:message],
|
|
38
|
+
value: value
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def validate_iban_format(record, attribute, value, options)
|
|
43
|
+
return if iban_format_valid?(value)
|
|
44
|
+
|
|
45
|
+
record.errors.add(
|
|
46
|
+
attribute,
|
|
47
|
+
:iban_format_not_valid,
|
|
48
|
+
message: options[:message],
|
|
49
|
+
value: value
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def validate_start_with_ch(record, attribute, value, options)
|
|
54
|
+
return if value.downcase.start_with?('ch')
|
|
55
|
+
|
|
56
|
+
record.errors.add(
|
|
57
|
+
attribute,
|
|
58
|
+
:must_start_with_ch,
|
|
59
|
+
message: options[:message],
|
|
60
|
+
value: value
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def iban_format_valid?(iban)
|
|
65
|
+
iban_numerified = numerify_iban(iban)
|
|
66
|
+
return false if iban_numerified.nil?
|
|
67
|
+
|
|
68
|
+
iban_numerified.to_i % 97 == 1
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def numerify_iban(iban)
|
|
72
|
+
return '' if iban.blank?
|
|
73
|
+
|
|
74
|
+
numerified = ''
|
|
75
|
+
code = iban.to_s.strip.gsub(/\s+/, '').upcase
|
|
76
|
+
(code[4..] + code[0..3]).each_byte do |byte|
|
|
77
|
+
numerified += case byte
|
|
78
|
+
# 0..9
|
|
79
|
+
when 48..57 then byte.chr
|
|
80
|
+
# 'A'..'Z'
|
|
81
|
+
when 65..90 then (byte - 55).to_s # 55 = 'A'.ord + 10
|
|
82
|
+
else
|
|
83
|
+
return nil
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
numerified
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
module ClassMethods
|
|
91
|
+
# Validates whether or not the specified iban is valid.
|
|
92
|
+
#
|
|
93
|
+
# class Account < ActiveRecord::Base
|
|
94
|
+
# validates_iban_format_of :iban
|
|
95
|
+
# end
|
|
96
|
+
#
|
|
97
|
+
def validates_iban_format_of(*attr_names)
|
|
98
|
+
validates_with IbanValidator, _merge_attributes(attr_names)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
alias validates_iban validates_iban_format_of
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/swiss_bank_validator/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'swiss_bank_validator'
|
|
7
|
+
spec.version = SwissBankValidator::VERSION
|
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
|
9
|
+
spec.authors = ['QoQa dev Team']
|
|
10
|
+
spec.email = ['dev@qoqa.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = 'All you need to validate a Swiss Iban'
|
|
13
|
+
spec.homepage = 'https://github.com/qoqa/swiss_bank_validator'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/qoqa/swiss_bank_validator'
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/qoqa/swiss_bank_validator/main/changelog.md'
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = 'exe'
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ['lib']
|
|
29
|
+
|
|
30
|
+
spec.add_dependency 'activemodel', '~> 6.0'
|
|
31
|
+
|
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 1.5'
|
|
34
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: swiss_bank_validator
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.5.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- QoQa dev Team
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-12-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activemodel
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '6.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '6.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rubocop
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.5'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.5'
|
|
55
|
+
description:
|
|
56
|
+
email:
|
|
57
|
+
- dev@qoqa.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".github/workflows/ruby.yml"
|
|
63
|
+
- ".gitignore"
|
|
64
|
+
- ".rubocop.yml"
|
|
65
|
+
- ".travis.yml"
|
|
66
|
+
- CODE_OF_CONDUCT.md
|
|
67
|
+
- Gemfile
|
|
68
|
+
- Gemfile.lock
|
|
69
|
+
- LICENSE.txt
|
|
70
|
+
- README.md
|
|
71
|
+
- Rakefile
|
|
72
|
+
- bin/console
|
|
73
|
+
- bin/setup
|
|
74
|
+
- changelog.md
|
|
75
|
+
- lib/swiss_bank_validator.rb
|
|
76
|
+
- lib/swiss_bank_validator/constants.rb
|
|
77
|
+
- lib/swiss_bank_validator/locale/de.yml
|
|
78
|
+
- lib/swiss_bank_validator/locale/en.yml
|
|
79
|
+
- lib/swiss_bank_validator/locale/fr.yml
|
|
80
|
+
- lib/swiss_bank_validator/validates_iban_format_of.rb
|
|
81
|
+
- lib/swiss_bank_validator/version.rb
|
|
82
|
+
- swiss_bank_validator.gemspec
|
|
83
|
+
homepage: https://github.com/qoqa/swiss_bank_validator
|
|
84
|
+
licenses:
|
|
85
|
+
- MIT
|
|
86
|
+
metadata:
|
|
87
|
+
homepage_uri: https://github.com/qoqa/swiss_bank_validator
|
|
88
|
+
source_code_uri: https://github.com/qoqa/swiss_bank_validator
|
|
89
|
+
changelog_uri: https://github.com/qoqa/swiss_bank_validator/main/changelog.md
|
|
90
|
+
post_install_message:
|
|
91
|
+
rdoc_options: []
|
|
92
|
+
require_paths:
|
|
93
|
+
- lib
|
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
|
+
requirements:
|
|
96
|
+
- - ">="
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: 2.7.0
|
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
requirements: []
|
|
105
|
+
rubygems_version: 3.1.4
|
|
106
|
+
signing_key:
|
|
107
|
+
specification_version: 4
|
|
108
|
+
summary: All you need to validate a Swiss Iban
|
|
109
|
+
test_files: []
|