czech_bank_account 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/czech_bank_account.gemspec +24 -0
- data/lib/czech_bank_account.rb +74 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bf0bda487c7a52123b38d09033fa57e1ea016bfebc83c53d5af758f35bfe3658
|
4
|
+
data.tar.gz: 6b78810e6b56bf48a2dba79caefc4715a8a9d29543e29922e4d8529072c4ddad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a307b2db6aa2290221a5f16fa91e443edb39812b65c67e0efe53f3c18cb4e28d79a5d54fe639f8ffd70b7afba2f10059fcb68f46d3665c4fc6124c873795a710
|
7
|
+
data.tar.gz: 645c525050898fccfe97909976019ee2f9339fff76436cce189af0f027ee8805c8747bdf81c56fd3e4cf4b08df54f9a72171c88f618dd1621b87786154d6978a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Premysl Donat
|
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,39 @@
|
|
1
|
+
# CzechBankAccount
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/czech_bank_account`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'czech_bank_account'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install czech_bank_account
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/czech_bank_account.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'czech_bank_account'
|
6
|
+
spec.version = '0.1.0'
|
7
|
+
spec.authors = ['Premysl Donat']
|
8
|
+
spec.email = ['pdonat@seznam.cz']
|
9
|
+
|
10
|
+
spec.summary = 'Library for working with czech bank account numbers'
|
11
|
+
spec.description = spec.description
|
12
|
+
spec.homepage = 'https://github.com/Masa331/czech_bank_account'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'activemodel'
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'active_model/validator'
|
2
|
+
|
3
|
+
module CzechBankAccount
|
4
|
+
class BankAccountValidator < ActiveModel::Validator
|
5
|
+
# http://www.cnb.cz/miranda2/export/sites/www.cnb.cz/cs/platebni_styk/pravni_predpisy/download/vyhl_169_2011.pdf
|
6
|
+
# http://www.cnb.cz/miranda2/export/sites/www.cnb.cz/cs/platebni_styk/ucty_kody_bank/download/kody_bank_CR.pdf
|
7
|
+
# http://www.cnb.cz/cs/platebni_styk/ucty_kody_bank/index.html
|
8
|
+
|
9
|
+
WEIGHTS = [6, 3, 7, 9, 10, 5, 8, 4, 2, 1]
|
10
|
+
KNOWN_CODES = ["0100", "0300", "0600", "0710", "0800", "2010", "2020", "2030", "2060", "2070", "2100", "2200", "2220", "2240", "2250", "2260", "2275", "2600", "2700", "3030", "3050", "3060", "3500", "4000", "4300", "5500", "5800", "6000", "6100", "6200", "6210", "6300", "6700", "6800", "7910", "7940", "7950", "7960", "7970", "7980", "7990", "8030", "8040", "8060", "8090", "8150", "8200", "8215", "8220", "8225", "8230", "8240", "8250", "8260", "8265", "8270", "8280", "8290", "8291", "8292", "8293", "8294"]
|
11
|
+
|
12
|
+
def validate(record)
|
13
|
+
if record.number.blank?
|
14
|
+
record.errors.add(:base, :number_is_blank)
|
15
|
+
end
|
16
|
+
|
17
|
+
if record.bank_code.blank?
|
18
|
+
record.errors.add(:base, :bank_code_is_blank)
|
19
|
+
end
|
20
|
+
|
21
|
+
validate_allowed_chars(record)
|
22
|
+
validate_number(record)
|
23
|
+
validate_bank_code(record)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def validate_allowed_chars(record)
|
29
|
+
return if record.number.blank?
|
30
|
+
|
31
|
+
unless record.number.match?(/\A[0-9-]*\z/)
|
32
|
+
record.errors.add :base, :number_includes_not_allowed_characters
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def validate_number(record)
|
37
|
+
return if record.number.blank?
|
38
|
+
return if record.number.count('-') > 1
|
39
|
+
|
40
|
+
prefix, number = record.number.split '-'
|
41
|
+
|
42
|
+
if prefix && prefix.length > 6
|
43
|
+
record.errors.add :base, :number_prefix_is_over_length_limit
|
44
|
+
return
|
45
|
+
end
|
46
|
+
|
47
|
+
if number && (number.length < 2 || number.length > 10)
|
48
|
+
record.errors.add :base, :number_is_over_or_under_length_limit
|
49
|
+
return
|
50
|
+
end
|
51
|
+
|
52
|
+
if prefix && weighted_sum(prefix) % 11 != 0
|
53
|
+
record.errors.add :base, :prefix_doesnt_pass_checksum
|
54
|
+
end
|
55
|
+
|
56
|
+
if number && weighted_sum(number) % 11 != 0
|
57
|
+
record.errors.add :base, :number_doesnt_pass_checksum
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def validate_bank_code(record)
|
62
|
+
unless KNOWN_CODES.include? record.bank_code
|
63
|
+
record.errors.add :base, :unknown_bank_code
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def weighted_sum(number)
|
68
|
+
normalized = number.rjust(10, '0')
|
69
|
+
chars = normalized.chars.map(&:to_i)
|
70
|
+
zipped = chars.zip WEIGHTS
|
71
|
+
zipped.inject(0) { |acc, pair| acc + pair.first * pair.last }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: czech_bank_account
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Premysl Donat
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-07 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '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: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- pdonat@seznam.cz
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- czech_bank_account.gemspec
|
53
|
+
- lib/czech_bank_account.rb
|
54
|
+
homepage: https://github.com/Masa331/czech_bank_account
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.7.7
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Library for working with czech bank account numbers
|
78
|
+
test_files: []
|