br_boleto 0.1.0 → 1.0.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/Gemfile.lock +3 -3
  4. data/README.markdown +196 -11
  5. data/Rakefile +5 -0
  6. data/br_boleto.gemspec +1 -1
  7. data/lib/br_boleto.rb +30 -12
  8. data/lib/br_boleto/{core/boleto.rb → boleto/base.rb} +83 -5
  9. data/lib/br_boleto/boleto/sicoob.rb +211 -0
  10. data/lib/br_boleto/calculos/modulo11_fator3197.rb +5 -5
  11. data/lib/br_boleto/helper/cpf_cnpj.rb +60 -0
  12. data/lib/br_boleto/helper/number.rb +15 -0
  13. data/lib/br_boleto/remessa/base.rb +89 -0
  14. data/lib/br_boleto/remessa/cnab240/base.rb +328 -0
  15. data/lib/br_boleto/remessa/cnab240/helper/header_arquivo.rb +186 -0
  16. data/lib/br_boleto/remessa/cnab240/helper/header_lote.rb +180 -0
  17. data/lib/br_boleto/remessa/cnab240/helper/segmento_p.rb +349 -0
  18. data/lib/br_boleto/remessa/cnab240/helper/segmento_q.rb +206 -0
  19. data/lib/br_boleto/remessa/cnab240/helper/segmento_r.rb +261 -0
  20. data/lib/br_boleto/remessa/cnab240/helper/segmento_s.rb +193 -0
  21. data/lib/br_boleto/remessa/cnab240/helper/trailer_arquivo.rb +88 -0
  22. data/lib/br_boleto/remessa/cnab240/helper/trailer_lote.rb +75 -0
  23. data/lib/br_boleto/remessa/cnab240/sicoob.rb +246 -0
  24. data/lib/br_boleto/remessa/lote.rb +52 -0
  25. data/lib/br_boleto/remessa/pagamento.rb +238 -0
  26. data/lib/br_boleto/string_methods.rb +21 -0
  27. data/lib/br_boleto/version.rb +2 -2
  28. data/test/br_boleto/{core/boleto_test.rb → boleto/base_test.rb} +107 -11
  29. data/test/br_boleto/{core → boleto}/sicoob_test.rb +60 -2
  30. data/test/br_boleto/remessa/base_test.rb +80 -0
  31. data/test/br_boleto/remessa/cnab240/base_test.rb +405 -0
  32. data/test/br_boleto/remessa/cnab240/helper/header_arquivo_test.rb +208 -0
  33. data/test/br_boleto/remessa/cnab240/helper/header_lote_test.rb +200 -0
  34. data/test/br_boleto/remessa/cnab240/helper/segmento_p_test.rb +390 -0
  35. data/test/br_boleto/remessa/cnab240/helper/segmento_q_test.rb +223 -0
  36. data/test/br_boleto/remessa/cnab240/helper/segmento_r_test.rb +260 -0
  37. data/test/br_boleto/remessa/cnab240/helper/segmento_s_test.rb +217 -0
  38. data/test/br_boleto/remessa/cnab240/helper/trailer_arquivo_test.rb +82 -0
  39. data/test/br_boleto/remessa/cnab240/helper/trailer_lote_test.rb +67 -0
  40. data/test/br_boleto/remessa/cnab240/sicoob_test.rb +347 -0
  41. data/test/br_boleto/remessa/lote_test.rb +49 -0
  42. data/test/br_boleto/remessa/pagamento_test.rb +339 -0
  43. data/test/factories/{boleto.rb → boleto/base.rb} +1 -1
  44. data/test/factories/{boleto_sicoob.rb → boleto/boleto_sicoob.rb} +1 -1
  45. data/test/factories/remessa/base.rb +13 -0
  46. data/test/factories/remessa/cnab240/base.rb +18 -0
  47. data/test/factories/remessa/cnab240/sicoob.rb +18 -0
  48. data/test/factories/remessa/lote.rb +7 -0
  49. data/test/factories/remessa/pagamento.rb +16 -0
  50. data/test/inheritance/boleto_test.rb +1 -1
  51. data/test/inheritance/sicoob_test.rb +1 -1
  52. metadata +65 -13
  53. data/lib/br_boleto/core/sicoob.rb +0 -169
@@ -0,0 +1,7 @@
1
+ # encoding: UTF-8
2
+
3
+ FactoryGirl.define do
4
+ factory :remessa_lote, class: BrBoleto::Remessa::Lote do
5
+ pagamentos { FactoryGirl.build(:remessa_pagamento) }
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+
3
+ FactoryGirl.define do
4
+ factory :remessa_pagamento, class: BrBoleto::Remessa::Pagamento do
5
+ nosso_numero "123456"
6
+ data_vencimento { Date.tomorrow }
7
+ valor_documento 100.123
8
+ documento_sacado "12345678901"
9
+ nome_sacado "TESTE NOME DO SACADO"
10
+ endereco_sacado "R. TESTE DO SACADO"
11
+ cep_sacado "89888000"
12
+ cidade_sacado "PIRÁPORA"
13
+ uf_sacado "SC"
14
+ bairro_sacado "Bairro"
15
+ end
16
+ end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'test_helper'
3
3
 
4
- class TesteBoleto < BrBoleto::Boleto
4
+ class TesteBoleto < BrBoleto::Boleto::Base
5
5
  def self.valor_documento_tamanho_maximo
6
6
  9_999.99 # Default 99999999.99
7
7
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'test_helper'
3
3
 
4
- class TesteSicoob < BrBoleto::Sicoob
4
+ class TesteSicoob < BrBoleto::Boleto::Sicoob
5
5
  def self.valor_documento_tamanho_maximo
6
6
  456.50 # Default 99999999.99
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: br_boleto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno M. Mergen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-27 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -59,6 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".travis.yml"
62
63
  - Gemfile
63
64
  - Gemfile.lock
64
65
  - History.txt
@@ -67,6 +68,8 @@ files:
67
68
  - Rakefile
68
69
  - br_boleto.gemspec
69
70
  - lib/br_boleto.rb
71
+ - lib/br_boleto/boleto/base.rb
72
+ - lib/br_boleto/boleto/sicoob.rb
70
73
  - lib/br_boleto/calculos/digitos.rb
71
74
  - lib/br_boleto/calculos/fator_vencimento.rb
72
75
  - lib/br_boleto/calculos/fatores_de_multiplicacao.rb
@@ -80,9 +83,25 @@ files:
80
83
  - lib/br_boleto/calculos/modulo11_fator_de9a2.rb
81
84
  - lib/br_boleto/calculos/modulo11_fator_de9a2_resto_x.rb
82
85
  - lib/br_boleto/calculos/modulo_numero_de_controle.rb
83
- - lib/br_boleto/core/boleto.rb
84
- - lib/br_boleto/core/sicoob.rb
86
+ - lib/br_boleto/helper/cpf_cnpj.rb
87
+ - lib/br_boleto/helper/number.rb
88
+ - lib/br_boleto/remessa/base.rb
89
+ - lib/br_boleto/remessa/cnab240/base.rb
90
+ - lib/br_boleto/remessa/cnab240/helper/header_arquivo.rb
91
+ - lib/br_boleto/remessa/cnab240/helper/header_lote.rb
92
+ - lib/br_boleto/remessa/cnab240/helper/segmento_p.rb
93
+ - lib/br_boleto/remessa/cnab240/helper/segmento_q.rb
94
+ - lib/br_boleto/remessa/cnab240/helper/segmento_r.rb
95
+ - lib/br_boleto/remessa/cnab240/helper/segmento_s.rb
96
+ - lib/br_boleto/remessa/cnab240/helper/trailer_arquivo.rb
97
+ - lib/br_boleto/remessa/cnab240/helper/trailer_lote.rb
98
+ - lib/br_boleto/remessa/cnab240/sicoob.rb
99
+ - lib/br_boleto/remessa/lote.rb
100
+ - lib/br_boleto/remessa/pagamento.rb
101
+ - lib/br_boleto/string_methods.rb
85
102
  - lib/br_boleto/version.rb
103
+ - test/br_boleto/boleto/base_test.rb
104
+ - test/br_boleto/boleto/sicoob_test.rb
86
105
  - test/br_boleto/calculos/digitos_test.rb
87
106
  - test/br_boleto/calculos/fator_vencimento_test.rb
88
107
  - test/br_boleto/calculos/fatores_de_multiplicacao_test.rb
@@ -96,10 +115,26 @@ files:
96
115
  - test/br_boleto/calculos/modulo11_fator_de9a2_test.rb
97
116
  - test/br_boleto/calculos/modulo11_test.rb
98
117
  - test/br_boleto/calculos/modulo_numero_de_controle_test.rb
99
- - test/br_boleto/core/boleto_test.rb
100
- - test/br_boleto/core/sicoob_test.rb
101
- - test/factories/boleto.rb
102
- - test/factories/boleto_sicoob.rb
118
+ - test/br_boleto/remessa/base_test.rb
119
+ - test/br_boleto/remessa/cnab240/base_test.rb
120
+ - test/br_boleto/remessa/cnab240/helper/header_arquivo_test.rb
121
+ - test/br_boleto/remessa/cnab240/helper/header_lote_test.rb
122
+ - test/br_boleto/remessa/cnab240/helper/segmento_p_test.rb
123
+ - test/br_boleto/remessa/cnab240/helper/segmento_q_test.rb
124
+ - test/br_boleto/remessa/cnab240/helper/segmento_r_test.rb
125
+ - test/br_boleto/remessa/cnab240/helper/segmento_s_test.rb
126
+ - test/br_boleto/remessa/cnab240/helper/trailer_arquivo_test.rb
127
+ - test/br_boleto/remessa/cnab240/helper/trailer_lote_test.rb
128
+ - test/br_boleto/remessa/cnab240/sicoob_test.rb
129
+ - test/br_boleto/remessa/lote_test.rb
130
+ - test/br_boleto/remessa/pagamento_test.rb
131
+ - test/factories/boleto/base.rb
132
+ - test/factories/boleto/boleto_sicoob.rb
133
+ - test/factories/remessa/base.rb
134
+ - test/factories/remessa/cnab240/base.rb
135
+ - test/factories/remessa/cnab240/sicoob.rb
136
+ - test/factories/remessa/lote.rb
137
+ - test/factories/remessa/pagamento.rb
103
138
  - test/inheritance/boleto_test.rb
104
139
  - test/inheritance/sicoob_test.rb
105
140
  - test/test_helper.rb
@@ -128,6 +163,8 @@ signing_key:
128
163
  specification_version: 4
129
164
  summary: Emissão de Boletos Bancários em Ruby
130
165
  test_files:
166
+ - test/br_boleto/boleto/base_test.rb
167
+ - test/br_boleto/boleto/sicoob_test.rb
131
168
  - test/br_boleto/calculos/digitos_test.rb
132
169
  - test/br_boleto/calculos/fator_vencimento_test.rb
133
170
  - test/br_boleto/calculos/fatores_de_multiplicacao_test.rb
@@ -141,11 +178,26 @@ test_files:
141
178
  - test/br_boleto/calculos/modulo11_fator_de9a2_test.rb
142
179
  - test/br_boleto/calculos/modulo11_test.rb
143
180
  - test/br_boleto/calculos/modulo_numero_de_controle_test.rb
144
- - test/br_boleto/core/boleto_test.rb
145
- - test/br_boleto/core/sicoob_test.rb
146
- - test/factories/boleto.rb
147
- - test/factories/boleto_sicoob.rb
181
+ - test/br_boleto/remessa/base_test.rb
182
+ - test/br_boleto/remessa/cnab240/base_test.rb
183
+ - test/br_boleto/remessa/cnab240/helper/header_arquivo_test.rb
184
+ - test/br_boleto/remessa/cnab240/helper/header_lote_test.rb
185
+ - test/br_boleto/remessa/cnab240/helper/segmento_p_test.rb
186
+ - test/br_boleto/remessa/cnab240/helper/segmento_q_test.rb
187
+ - test/br_boleto/remessa/cnab240/helper/segmento_r_test.rb
188
+ - test/br_boleto/remessa/cnab240/helper/segmento_s_test.rb
189
+ - test/br_boleto/remessa/cnab240/helper/trailer_arquivo_test.rb
190
+ - test/br_boleto/remessa/cnab240/helper/trailer_lote_test.rb
191
+ - test/br_boleto/remessa/cnab240/sicoob_test.rb
192
+ - test/br_boleto/remessa/lote_test.rb
193
+ - test/br_boleto/remessa/pagamento_test.rb
194
+ - test/factories/boleto/base.rb
195
+ - test/factories/boleto/boleto_sicoob.rb
196
+ - test/factories/remessa/base.rb
197
+ - test/factories/remessa/cnab240/base.rb
198
+ - test/factories/remessa/cnab240/sicoob.rb
199
+ - test/factories/remessa/lote.rb
200
+ - test/factories/remessa/pagamento.rb
148
201
  - test/inheritance/boleto_test.rb
149
202
  - test/inheritance/sicoob_test.rb
150
- - test/test_helper.rb
151
203
  has_rdoc:
@@ -1,169 +0,0 @@
1
- # encoding: utf-8
2
- module BrBoleto
3
- module Core
4
- # Implementação de emissão de boleto bancário pelo Banco Sicoob.
5
- #
6
- # === Documentação Implementada
7
- #
8
- # A documentação na qual essa implementação foi baseada está localizada na pasta
9
- # 'documentacoes_dos_boletos/sicoob' dentro dessa biblioteca.
10
- #
11
- # === Código da Carteira
12
- #
13
- # '1' - Cobrança SEM registro
14
- # '9' - Cobrança COM registro
15
- #
16
- class Sicoob < Boleto
17
- # Tamanho máximo de uma agência no Banco Sicoob.
18
- # <b>Método criado justamente para ficar documentado o tamanho máximo aceito até a data corrente.</b>
19
- #
20
- # @return [Fixnum] 4
21
- #
22
- def self.tamanho_maximo_agencia
23
- 4
24
- end
25
-
26
- # Tamanho máximo do codigo cedente no Banco Sicoob.
27
- # <b>Método criado justamente para ficar documentado o tamanho máximo aceito até a data corrente.</b>
28
- #
29
- # @return [Fixnum] 7
30
- #
31
- def self.tamanho_maximo_codigo_cedente
32
- 7
33
- end
34
-
35
- # Tamanho máximo do numero do documento no Boleto.
36
- # <b>Método criado justamente para ficar documentado o tamanho máximo aceito até a data corrente.</b>
37
- #
38
- # @return [Fixnum] 6
39
- #
40
- def self.tamanho_maximo_numero_documento
41
- 7
42
- end
43
-
44
- # <b>Carteiras suportadas.</b>
45
- #
46
- # <b>Método criado para validar se a carteira informada é suportada.</b>
47
- #
48
- # @return [Array]
49
- #
50
- def self.carteiras_suportadas
51
- %w[1 3]
52
- end
53
-
54
- # Validações para os campos abaixo:
55
- #
56
- # * Agencia
57
- # * Codigo Cedente
58
- # * Número do documento
59
- #
60
- # Se você quiser sobrescrever os metodos, <b>ficará a sua responsabilidade.</b>
61
- # Basta você sobrescrever os métodos de validação:
62
- #
63
- # class Sicoob < BrBoleto::Core::Sicoob
64
- # def self.tamanho_maximo_agencia
65
- # 6
66
- # end
67
- #
68
- # def self.tamanho_maximo_codigo_cedente
69
- # 9
70
- # end
71
- #
72
- # def self.tamanho_maximo_numero_documento
73
- # 10
74
- # end
75
- # end
76
- #
77
- # Obs.: Mudar as regras de validação podem influenciar na emissão do boleto em si.
78
- # Talvez você precise analisar o efeito no #codigo_de_barras e na #linha_digitável (ambos podem ser
79
- # sobreescritos também).
80
- #
81
- validates :agencia, :codigo_cedente, presence: true
82
-
83
- validates :agencia, length: { maximum: tamanho_maximo_agencia }, if: :deve_validar_agencia?
84
- validates :codigo_cedente, length: { maximum: tamanho_maximo_codigo_cedente }, if: :deve_validar_codigo_cedente?
85
- validates :numero_documento, length: { maximum: tamanho_maximo_numero_documento }, if: :deve_validar_numero_documento?
86
-
87
- validates :carteira, inclusion: { in: ->(object) { object.class.carteiras_suportadas } }, if: :deve_validar_carteira?
88
-
89
- # @return [String] 4 caracteres
90
- #
91
- def agencia
92
- @agencia.to_s.rjust(4, '0') if @agencia.present?
93
- end
94
-
95
- # @return [String] 7 caracteres
96
- # O Código do cedente é o mesmo que o codigo do beneficiário
97
- def codigo_cedente
98
- @codigo_cedente.to_s.rjust(7, '0') if @codigo_cedente.present?
99
- end
100
-
101
- # @return [String] 6 caracteres
102
- #
103
- def numero_documento
104
- @numero_documento.to_s.rjust(7, '0') if @numero_documento.present?
105
- end
106
-
107
- # @return [String] Código do Banco descrito na documentação.
108
- #
109
- def codigo_banco
110
- '756'
111
- end
112
-
113
- # @return [String] Dígito do código do banco descrito na documentação.
114
- #
115
- def digito_codigo_banco
116
- '0'
117
- end
118
-
119
- # Campo Agência / Código do Cedente
120
- #
121
- # @return [String]
122
- #
123
- def agencia_codigo_cedente
124
- "#{agencia} / #{codigo_cedente}"
125
- end
126
-
127
- # O nosso número descrino na documentação é formado pelo dois ultimos digitos do ano autal e
128
- # por outros 6 digitos que o clinte usara para numerar os documentos, assim sendo composto por 8 dígitos.
129
- #
130
- # @return [String]
131
- #
132
- def nosso_numero
133
- "#{numero_documento}-#{digito_verificador_nosso_numero}"
134
- end
135
-
136
-
137
- # === Código de barras do banco
138
- #
139
- # ___________________________________________________________
140
- # | Posição | Tamanho | Descrição |
141
- # |---------|---------|---------------------------------------|
142
- # | 20 - 20 | 01 | Código da carteira |
143
- # | 21 - 24 | 04 | Código da agência |
144
- # | 25 - 26 | 02 | Código da modalidade de cobrança (01) |
145
- # | 27 - 33 | 07 | Código do Cedente |
146
- # | 34 - 41 | 08 | Nosso Número do título |
147
- # | 42 - 44 | 03 | Número da Parcela do Título (001) |
148
- # |___________________________________________________________|
149
- #
150
- # @return [String]
151
- #
152
- def codigo_de_barras_do_banco
153
- "#{carteira}#{agencia}#{modalidade_cobranca}#{codigo_cedente}#{nosso_numero.gsub('-','')}#{parcelas}"
154
- end
155
-
156
- def digito_verificador_nosso_numero
157
- BrBoleto::Calculos::Modulo11Fator3197.new("#{agencia}#{codigo_cedente.rjust(10, '0')}#{numero_documento}")
158
- end
159
-
160
- def modalidade_cobranca
161
- '01'
162
- end
163
-
164
- def parcelas
165
- '001'
166
- end
167
- end
168
- end
169
- end