verificador_boleto_br 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 +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +100 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/verificador_boleto_br.rb +21 -0
- data/lib/verificador_boleto_br/arrecadation_slip.rb +122 -0
- data/lib/verificador_boleto_br/bank_slip.rb +102 -0
- data/lib/verificador_boleto_br/calculus/module10.rb +24 -0
- data/lib/verificador_boleto_br/calculus/module11.rb +23 -0
- data/lib/verificador_boleto_br/data/Banks.json +159 -0
- data/lib/verificador_boleto_br/data/Dealerships.json +3222 -0
- data/lib/verificador_boleto_br/operationals.rb +11 -0
- data/lib/verificador_boleto_br/version.rb +3 -0
- data/verificador_boleto_br.gemspec +29 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c34bfe9726e78a7a81a3063c9d0a96c000cdf786a7894daa97b0a28dc92e1ba9
|
4
|
+
data.tar.gz: c45ddc477b9337542cda021ed0b1bbb3d1e6bf4a2452c01e80bc4382c1ee52d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 266359f9f9857327ee55f0ce6645a46eae1a66f416e42c9d76e0bb7dc7aa72e36edd6a77e50bdfaa882ea2e3b8995335d460aae1d930d6ba128d86f4014643e3
|
7
|
+
data.tar.gz: f9baa289c2f9a94a38bde0aff4bf726e8be97e6f3fb34335eb974e84fbf6af469ea3537ee1a53de90e31412fe11abda0abe8743ee5e5bedac2cd03f8b6151af7
|
data/.gitignore
ADDED
data/.rspec
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 ogabrielhamdan@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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
VerificadorBoletoBr (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
VerificadorBoletoBr!
|
30
|
+
bundler (~> 2.0.1)
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Gabriel Hamdan
|
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,100 @@
|
|
1
|
+
# VerificadorBoletoBr
|
2
|
+
|
3
|
+
Essa gem o ajudará a identificar boletos bancários nos seguinte items:
|
4
|
+
* Banco
|
5
|
+
* Valor
|
6
|
+
* Data de Vencimento
|
7
|
+
|
8
|
+
e, no caso de boleto de arrecadação:
|
9
|
+
* Segmento
|
10
|
+
* Concessionario (Emissor)
|
11
|
+
* Valor
|
12
|
+
* Validade (se disponível e "padrão" (🤣🤣🤣🤣) Febraban)
|
13
|
+
|
14
|
+
E ainda conferir a **validade** dos mesmos.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'verificador_boleto_br'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install verificador_boleto_br
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
````ruby
|
35
|
+
require './lib/verificador_boleto_br'
|
36
|
+
>> slip = VerificadorBoletoBr.check('34191 75801 03928 662935 80573 180009 4 67700000007388')
|
37
|
+
=> #<VerificadorBoletoBr::BankSlip:0x00007ff4c3933478 @digitable_line="34191 75801 03928 662935 80573 180009 4 67700000007388">
|
38
|
+
````
|
39
|
+
It will return the respective slip class with its methods:
|
40
|
+
|
41
|
+
### BankSlip
|
42
|
+
|
43
|
+
````ruby
|
44
|
+
>> slip.valid?
|
45
|
+
=> true
|
46
|
+
>> slip.bank_code
|
47
|
+
=> 341
|
48
|
+
>> slip.currency_code
|
49
|
+
=> 9
|
50
|
+
>> slip.value_in_cents
|
51
|
+
=> 7388
|
52
|
+
>> slip.value
|
53
|
+
=> 73.88
|
54
|
+
>> slip.due_date
|
55
|
+
=> #<Date: 2016-04-20 ((2457499j,0s,0n),+0s,2299161j)
|
56
|
+
````
|
57
|
+
|
58
|
+
### ArrecadationSlip (Concessionária)
|
59
|
+
|
60
|
+
````ruby
|
61
|
+
>> slip = VerificadorBoletoBr.check('858900000018 097802702000 323858108001 011520190292')
|
62
|
+
=> #<VerificadorBoletoBr::ArrecadationSlip:0x00007ff4c50c8d40 @digitable_line="858900000018 097802702000 323858108001 011520190292", @errors=[]>
|
63
|
+
>> slip.valid?
|
64
|
+
=> true
|
65
|
+
>> slip.value_in_cents
|
66
|
+
=> 10978
|
67
|
+
>> slip.value
|
68
|
+
=> 109.78
|
69
|
+
>> slip.due_date
|
70
|
+
=> nil # if unavailable
|
71
|
+
>> slip.segment
|
72
|
+
=> "Órgãos Governamentais"
|
73
|
+
>> slip.identification
|
74
|
+
=> "Guia GPS - INSS"
|
75
|
+
````
|
76
|
+
|
77
|
+
You can access the slip classes directly if you want.
|
78
|
+
|
79
|
+
## Development
|
80
|
+
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
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).
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/VerificadorBoletoBr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
92
|
+
|
93
|
+
## Code of Conduct
|
94
|
+
|
95
|
+
Everyone interacting in the project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/VerificadorBoletoBr/blob/master/CODE_OF_CONDUCT.md).
|
96
|
+
|
97
|
+
## SPECIAL THANKS
|
98
|
+
|
99
|
+
Encontrei a lista de identificadores de bolego no repositório do Rodrigo Stuchi (https://github.com/rod-stuchi)
|
100
|
+
Obrigado cara.. não sei a origem dos dados (porque não consegui com a Febraban) mas parabens ;)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "VerificadorBoletoBr"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "./verificador_boleto_br/version"
|
2
|
+
require_relative "./verificador_boleto_br/operationals"
|
3
|
+
require_relative "./verificador_boleto_br/calculus/module10"
|
4
|
+
require_relative "./verificador_boleto_br/calculus/module11"
|
5
|
+
require_relative "./verificador_boleto_br/arrecadation_slip"
|
6
|
+
require_relative "./verificador_boleto_br/bank_slip"
|
7
|
+
|
8
|
+
require 'date'
|
9
|
+
|
10
|
+
module VerificadorBoletoBr
|
11
|
+
include Operationals
|
12
|
+
def self.check(digitable_line)
|
13
|
+
if digitable_line.gsub(/( |\.|-)/, '').size.eql?(47)
|
14
|
+
BankSlip.new(digitable_line)
|
15
|
+
elsif digitable_line.gsub(/( |\.|-)/, '').size.eql?(48)
|
16
|
+
ArrecadationSlip.new(digitable_line)
|
17
|
+
else
|
18
|
+
raise ArgumentError, 'Invalid Digitable Line'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module VerificadorBoletoBr
|
4
|
+
class ArrecadationSlip
|
5
|
+
|
6
|
+
include VerificadorBoletoBr::Operationals
|
7
|
+
include VerificadorBoletoBr::Calculus::Module10
|
8
|
+
include VerificadorBoletoBr::Calculus::Module11
|
9
|
+
|
10
|
+
attr_accessor :digitable_line, :errors
|
11
|
+
|
12
|
+
def initialize(cod)
|
13
|
+
@digitable_line = cod
|
14
|
+
raise ArgumentError, 'Expected String' unless @digitable_line.class.eql?(String)
|
15
|
+
raise ArgumentError, 'Invalid Digitable Line' unless clean_digitable_line.size == 48
|
16
|
+
raise ArgumentError, 'Boleto Não é de Arrecadação' unless @digitable_line[0] == '8'
|
17
|
+
|
18
|
+
@errors = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def clean_digitable_line
|
22
|
+
clean_masks(@digitable_line)
|
23
|
+
end
|
24
|
+
|
25
|
+
def verification_digit
|
26
|
+
clean_digitable_line[3].to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
def value_in_cents
|
30
|
+
digitable_line_without_dvs[4..14].to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
def value
|
34
|
+
value_in_cents.to_f / 100
|
35
|
+
end
|
36
|
+
|
37
|
+
def due_date
|
38
|
+
begin
|
39
|
+
Date.parse(digitable_line_without_dvs[-6..-1])
|
40
|
+
rescue
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def segment
|
46
|
+
case clean_digitable_line[1]
|
47
|
+
when '1'
|
48
|
+
'Prefeitura'
|
49
|
+
when '2'
|
50
|
+
'Saneamento'
|
51
|
+
when '3'
|
52
|
+
'Energia Elétrica e Gás'
|
53
|
+
when '4'
|
54
|
+
'Telefonia'
|
55
|
+
when '5'
|
56
|
+
'Órgãos Governamentais'
|
57
|
+
when '6'
|
58
|
+
'Empresas / Órgãos com CNPJ.'
|
59
|
+
when '7'
|
60
|
+
'Multa de trânsito'
|
61
|
+
when '9'
|
62
|
+
'Uso exclusivo do banco'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def identification
|
67
|
+
begin
|
68
|
+
JSON.parse(File.read('lib/verificador_boleto_br/data/Dealerships.json'))
|
69
|
+
.select { |d| d['code'] == clean_digitable_line[15..18] && d['segment'] == clean_digitable_line[1].to_i }[0]["dealership"]
|
70
|
+
rescue
|
71
|
+
"Boleto de #{segment}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def bacen_module
|
76
|
+
case clean_digitable_line[2]
|
77
|
+
when '6'
|
78
|
+
'modulo10'
|
79
|
+
when '7'
|
80
|
+
'modulo10'
|
81
|
+
when '8'
|
82
|
+
'modulo11'
|
83
|
+
when '9'
|
84
|
+
'modulo11'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def valid?
|
89
|
+
global_validity && !groups_validity.map { |group| group[:valid] }.include?(false)
|
90
|
+
end
|
91
|
+
|
92
|
+
def groups_validity
|
93
|
+
grouped_digitable_line.map do |group|
|
94
|
+
dv = send(bacen_module, group[:num]).to_s
|
95
|
+
valid = dv.eql?(group[:dv])
|
96
|
+
errors << "Campo #{group[:group]}" unless valid
|
97
|
+
{
|
98
|
+
group: group[:group],
|
99
|
+
valid: valid
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def global_validity
|
105
|
+
send(bacen_module, digitable_line_without_dvs[0..2] + digitable_line_without_dvs[4..-1]) == verification_digit
|
106
|
+
end
|
107
|
+
|
108
|
+
def grouped_digitable_line
|
109
|
+
clean_digitable_line.scan(/.{1,12}/).each_with_index.map do |group, index|
|
110
|
+
{
|
111
|
+
group: index,
|
112
|
+
num: group[0..-2],
|
113
|
+
dv: group[-1]
|
114
|
+
}
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def digitable_line_without_dvs
|
119
|
+
grouped_digitable_line.map { |group| group[:num] }.join
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|