boleto_bancario 0.0.1.beta

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.
Files changed (47) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Changelog.markdown +6 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +22 -0
  7. data/Planning.markdown +131 -0
  8. data/README.markdown +208 -0
  9. data/Rakefile +9 -0
  10. data/TODO.markdown +5 -0
  11. data/boleto_bancario.gemspec +25 -0
  12. data/documentacoes_dos_boletos/Bradesco/Manual_BRADESCO.PDF +0 -0
  13. data/lib/boleto_bancario/calculos/digitos.rb +35 -0
  14. data/lib/boleto_bancario/calculos/fator_vencimento.rb +87 -0
  15. data/lib/boleto_bancario/calculos/fatores_de_multiplicacao.rb +67 -0
  16. data/lib/boleto_bancario/calculos/linha_digitavel.rb +158 -0
  17. data/lib/boleto_bancario/calculos/modulo10.rb +83 -0
  18. data/lib/boleto_bancario/calculos/modulo11.rb +54 -0
  19. data/lib/boleto_bancario/calculos/modulo11_fator_de2a7.rb +97 -0
  20. data/lib/boleto_bancario/calculos/modulo11_fator_de2a9.rb +83 -0
  21. data/lib/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero.rb +29 -0
  22. data/lib/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x.rb +101 -0
  23. data/lib/boleto_bancario/core/banco_brasil.rb +532 -0
  24. data/lib/boleto_bancario/core/boleto.rb +525 -0
  25. data/lib/boleto_bancario/core/bradesco.rb +285 -0
  26. data/lib/boleto_bancario/core/itau.rb +455 -0
  27. data/lib/boleto_bancario/core/santander.rb +274 -0
  28. data/lib/boleto_bancario/version.rb +4 -0
  29. data/lib/boleto_bancario.rb +83 -0
  30. data/spec/boleto_bancario/calculos/digitos_spec.rb +19 -0
  31. data/spec/boleto_bancario/calculos/fator_vencimento_spec.rb +59 -0
  32. data/spec/boleto_bancario/calculos/fatores_de_multiplicacao_spec.rb +69 -0
  33. data/spec/boleto_bancario/calculos/linha_digitavel_spec.rb +57 -0
  34. data/spec/boleto_bancario/calculos/modulo10_spec.rb +49 -0
  35. data/spec/boleto_bancario/calculos/modulo11_fator_de2a7_spec.rb +43 -0
  36. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero_spec.rb +39 -0
  37. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb +61 -0
  38. data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x_spec.rb +37 -0
  39. data/spec/boleto_bancario/calculos/modulo11_spec.rb +19 -0
  40. data/spec/boleto_bancario/core/banco_brasil_spec.rb +383 -0
  41. data/spec/boleto_bancario/core/boleto_spec.rb +102 -0
  42. data/spec/boleto_bancario/core/bradesco_spec.rb +170 -0
  43. data/spec/boleto_bancario/core/itau_spec.rb +336 -0
  44. data/spec/boleto_bancario/core/santander_spec.rb +135 -0
  45. data/spec/shared_examples/boleto_bancario_shared_example.rb +164 -0
  46. data/spec/spec_helper.rb +14 -0
  47. metadata +221 -0
@@ -0,0 +1,164 @@
1
+ shared_examples_for 'boleto bancario' do
2
+ describe "on validations" do
3
+ before do
4
+ subject.should respond_to(:cedente, :endereco_cedente, :valor_documento, :numero_documento)
5
+ subject.should respond_to(:carteira, :sacado, :documento_sacado, :data_vencimento)
6
+ end
7
+
8
+ it { should have_valid(:cedente).when('Razao Social') }
9
+ it { should_not have_valid(:cedente).when(nil, '') }
10
+
11
+ it { should have_valid(:endereco_cedente).when('Rua Itapaiuna') }
12
+ it { should_not have_valid(:endereco_cedente).when(nil, '') }
13
+
14
+ it { should have_valid(:valor_documento).when('0900') }
15
+ it { should_not have_valid(:valor_documento).when(nil, '') }
16
+
17
+ it { should have_valid(:numero_documento).when('09890') }
18
+ it { should_not have_valid(:numero_documento).when(nil, '') }
19
+
20
+ it { should have_valid(:carteira).when('10', '75') }
21
+ it { should_not have_valid(:carteira).when(nil, '') }
22
+
23
+ it { should have_valid(:sacado).when('Teste', 'Outro Teste') }
24
+ it { should_not have_valid(:sacado).when(nil, '') }
25
+
26
+ it { should have_valid(:documento_sacado).when('112.167.084-95', '613.318.746-88') }
27
+ it { should_not have_valid(:documento_sacado).when(nil, '') }
28
+
29
+ it { should have_valid(:data_vencimento).when(Date.today) }
30
+ it { should_not have_valid(:data_vencimento).when('', nil, '01/10/2012', '2012-10-2012') }
31
+ end
32
+
33
+ describe "#to_partial_path" do
34
+ it { should respond_to(:to_partial_path) }
35
+ end
36
+
37
+ describe "#persisted?" do
38
+ before { subject.should respond_to(:persisted?) }
39
+
40
+ its(:persisted?) { should be false }
41
+ end
42
+
43
+ describe "#codigo_do_banco" do
44
+ before { subject.should respond_to(:codigo_banco) }
45
+
46
+ it { expect { subject.codigo_banco }.to_not raise_error(NotImplementedError) }
47
+ end
48
+
49
+ describe "#digito_do_codigo_do_banco" do
50
+ before { subject.should respond_to(:digito_codigo_banco) }
51
+
52
+ it { expect { subject.digito_codigo_banco }.to_not raise_error(NotImplementedError) }
53
+ end
54
+
55
+ describe "#codigo_banco_formatado" do
56
+ before { subject.should respond_to(:codigo_banco_formatado) }
57
+
58
+ it "should format the 'codigo_banco' with digit" do
59
+ subject.stub(:codigo_banco).and_return('001')
60
+ subject.stub(:digito_codigo_banco).and_return('9')
61
+ subject.codigo_banco_formatado.should eq '001-9'
62
+ end
63
+ end
64
+
65
+ describe "#agencia_codigo_cedente" do
66
+ before { subject.should respond_to(:agencia_codigo_cedente) }
67
+
68
+ it { expect { subject.agencia_codigo_cedente }.to_not raise_error(NotImplementedError) }
69
+ end
70
+
71
+ describe "#nosso_numero" do
72
+ before { subject.should respond_to(:nosso_numero) }
73
+
74
+ it { expect { subject.nosso_numero }.to_not raise_error(NotImplementedError) }
75
+ end
76
+
77
+ describe "#carteira_formatada" do
78
+ it { should respond_to(:carteira, :carteira_formatada) }
79
+ end
80
+
81
+ describe "#codigo_de_barras_do_banco" do
82
+ before { subject.should respond_to(:codigo_de_barras_do_banco) }
83
+
84
+ it { expect { subject.codigo_de_barras_do_banco }.to_not raise_error(NotImplementedError) }
85
+ end
86
+
87
+ describe "#valor_formatado_para_codigo_de_barras" do
88
+ before do
89
+ described_class.new.should respond_to(:valor_documento)
90
+ described_class.new.should respond_to(:valor_formatado_para_codigo_de_barras)
91
+ end
92
+
93
+ context "when period" do
94
+ subject { described_class.new(:valor_documento => 123.45) }
95
+
96
+ its(:valor_formatado_para_codigo_de_barras) { should eq '0000012345' }
97
+ end
98
+
99
+ context "when comma" do
100
+ subject { described_class.new(:valor_documento => '1.000,45') }
101
+
102
+ its(:valor_formatado_para_codigo_de_barras) { should eq '0000100045' }
103
+ end
104
+
105
+ context "when integer" do
106
+ subject { described_class.new(:valor_documento => 1_999) }
107
+
108
+ its(:valor_formatado_para_codigo_de_barras) { should eq '0000001999' }
109
+ end
110
+ end
111
+
112
+ describe "#codigo_de_barras" do
113
+ before { subject.should respond_to(:codigo_de_barras) }
114
+
115
+ it "should return the barcode with DAC (barcode digit)" do
116
+ subject.stub(:codigo_de_barras_padrao).and_return('341916670000012345')
117
+ subject.stub(:codigo_de_barras_do_banco).and_return('1101234567880057123457000')
118
+ subject.codigo_de_barras.should eq '34196166700000123451101234567880057123457000'
119
+ end
120
+ end
121
+
122
+ describe "#codigo_de_barras_padrao" do
123
+ before { subject.should respond_to(:codigo_de_barras_padrao, :valor_documento) }
124
+
125
+ context "barcode positions" do
126
+ let(:boleto) { described_class.new(:valor_documento => 190.99, :data_vencimento => Date.parse('2012-10-20')) }
127
+
128
+ it "should return the first 18 positions of barcode" do
129
+ boleto.stub(:codigo_banco).and_return('341')
130
+ boleto.codigo_de_barras_padrao.should eq '341954920000019099'
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "#digito_codigo_de_barras" do
136
+ before { subject.should respond_to(:digito_codigo_de_barras) }
137
+
138
+ context "using the Itau docs example" do
139
+ it "should calculate the digit using the modulo 11 factors 2 until 9" do
140
+ subject.stub(:codigo_de_barras_padrao).and_return('341916670000012345')
141
+ subject.stub(:codigo_de_barras_do_banco).and_return('1101234567880057123457000')
142
+ subject.digito_codigo_de_barras.should eq '6'
143
+ end
144
+ end
145
+ end
146
+
147
+ describe "#linha_digitavel" do
148
+ before { subject.should respond_to(:linha_digitavel) }
149
+
150
+ it "should return the digital line" do
151
+ subject.stub(:codigo_de_barras).and_return('39998100100000311551111122222500546666666001')
152
+ subject.linha_digitavel.should eq '39991.11119 22222.500542 66666.660015 8 10010000031155'
153
+ end
154
+ end
155
+
156
+ describe "#fator_de_vencimento" do
157
+ before { subject.should respond_to(:fator_de_vencimento) }
158
+
159
+ it "should calculate the expiration factor" do
160
+ subject.data_vencimento = Date.parse('2002-05-11')
161
+ subject.fator_de_vencimento.should eq '1677'
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,14 @@
1
+ require 'boleto_bancario'
2
+ require 'valid_attribute'
3
+
4
+ Dir[File.join(File.dirname(__FILE__), 'shared_examples/**/*.rb')].each do |file|
5
+ require(file)
6
+ end
7
+
8
+ if ENV['COVERAGE']
9
+ require 'simplecov'
10
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
11
+ SimpleCov.start do
12
+ add_filter "/spec/"
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boleto_bancario
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.beta
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Tomas D'Stefano
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activemodel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.2'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.11'
62
+ - !ruby/object:Gem::Dependency
63
+ name: valid_attribute
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.9'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.9'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '0.2'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.2'
110
+ - !ruby/object:Gem::Dependency
111
+ name: simplecov-html
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '0.7'
126
+ description: Emissão de Boletos Bancários em Ruby
127
+ email:
128
+ - tomas_stefano@successoft.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - .rvmrc
136
+ - Changelog.markdown
137
+ - Gemfile
138
+ - LICENSE
139
+ - Planning.markdown
140
+ - README.markdown
141
+ - Rakefile
142
+ - TODO.markdown
143
+ - boleto_bancario.gemspec
144
+ - documentacoes_dos_boletos/Bradesco/Manual_BRADESCO.PDF
145
+ - lib/boleto_bancario.rb
146
+ - lib/boleto_bancario/calculos/digitos.rb
147
+ - lib/boleto_bancario/calculos/fator_vencimento.rb
148
+ - lib/boleto_bancario/calculos/fatores_de_multiplicacao.rb
149
+ - lib/boleto_bancario/calculos/linha_digitavel.rb
150
+ - lib/boleto_bancario/calculos/modulo10.rb
151
+ - lib/boleto_bancario/calculos/modulo11.rb
152
+ - lib/boleto_bancario/calculos/modulo11_fator_de2a7.rb
153
+ - lib/boleto_bancario/calculos/modulo11_fator_de2a9.rb
154
+ - lib/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero.rb
155
+ - lib/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x.rb
156
+ - lib/boleto_bancario/core/banco_brasil.rb
157
+ - lib/boleto_bancario/core/boleto.rb
158
+ - lib/boleto_bancario/core/bradesco.rb
159
+ - lib/boleto_bancario/core/itau.rb
160
+ - lib/boleto_bancario/core/santander.rb
161
+ - lib/boleto_bancario/version.rb
162
+ - spec/boleto_bancario/calculos/digitos_spec.rb
163
+ - spec/boleto_bancario/calculos/fator_vencimento_spec.rb
164
+ - spec/boleto_bancario/calculos/fatores_de_multiplicacao_spec.rb
165
+ - spec/boleto_bancario/calculos/linha_digitavel_spec.rb
166
+ - spec/boleto_bancario/calculos/modulo10_spec.rb
167
+ - spec/boleto_bancario/calculos/modulo11_fator_de2a7_spec.rb
168
+ - spec/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero_spec.rb
169
+ - spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb
170
+ - spec/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x_spec.rb
171
+ - spec/boleto_bancario/calculos/modulo11_spec.rb
172
+ - spec/boleto_bancario/core/banco_brasil_spec.rb
173
+ - spec/boleto_bancario/core/boleto_spec.rb
174
+ - spec/boleto_bancario/core/bradesco_spec.rb
175
+ - spec/boleto_bancario/core/itau_spec.rb
176
+ - spec/boleto_bancario/core/santander_spec.rb
177
+ - spec/shared_examples/boleto_bancario_shared_example.rb
178
+ - spec/spec_helper.rb
179
+ homepage: https://github.com/tomas-stefano/boleto_bancario
180
+ licenses: []
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ! '>'
195
+ - !ruby/object:Gem::Version
196
+ version: 1.3.1
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 1.8.24
200
+ signing_key:
201
+ specification_version: 3
202
+ summary: Emissão de Boletos Bancários em Ruby
203
+ test_files:
204
+ - spec/boleto_bancario/calculos/digitos_spec.rb
205
+ - spec/boleto_bancario/calculos/fator_vencimento_spec.rb
206
+ - spec/boleto_bancario/calculos/fatores_de_multiplicacao_spec.rb
207
+ - spec/boleto_bancario/calculos/linha_digitavel_spec.rb
208
+ - spec/boleto_bancario/calculos/modulo10_spec.rb
209
+ - spec/boleto_bancario/calculos/modulo11_fator_de2a7_spec.rb
210
+ - spec/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero_spec.rb
211
+ - spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb
212
+ - spec/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x_spec.rb
213
+ - spec/boleto_bancario/calculos/modulo11_spec.rb
214
+ - spec/boleto_bancario/core/banco_brasil_spec.rb
215
+ - spec/boleto_bancario/core/boleto_spec.rb
216
+ - spec/boleto_bancario/core/bradesco_spec.rb
217
+ - spec/boleto_bancario/core/itau_spec.rb
218
+ - spec/boleto_bancario/core/santander_spec.rb
219
+ - spec/shared_examples/boleto_bancario_shared_example.rb
220
+ - spec/spec_helper.rb
221
+ has_rdoc: