conectiva-boleto_bancario 0.0.2.beta

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