cnab 0.3.0 → 0.4.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.
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/cnab.png)](http://badge.fury.io/rb/cnab) [![Build Status](https://travis-ci.org/zertico/cnab.png)](https://travis-ci.org/zertico/cnab) [![Coverage Status](https://coveralls.io/repos/zertico/cnab/badge.png?branch=master)](https://coveralls.io/r/zertico/cnab) [![Code Climate](https://codeclimate.com/github/zertico/cnab.png)](https://codeclimate.com/github/zertico/cnab)
4
4
 
5
- Gem used to parse return from Brazil banks in format of cnab files. It is based on the version 08.7 of the cnab.
6
- Right now it has support only for Segmento T and Segmento U.
5
+ Gem used to parse return from Brazil banks in format of cnab files.
6
+ Right now it has support only for Segmento T and Segmento U. By default, it will parse based on the version 08.7.
7
7
 
8
8
  ## Installation
9
9
 
@@ -33,9 +33,17 @@ If you need to merge the segments T and U, just pass true as the optional parame
33
33
  cnab = Cnab.parse('path/to/your/file', true)
34
34
  ```
35
35
 
36
+ If you need to parse a cnab file of another version, just pass it as the second optional parameter:
37
+
38
+ ```ruby
39
+ cnab = Cnab.parse('path/to/your/file', true, 'santander')
40
+ ```
41
+
36
42
  ## TODO
37
43
 
38
44
  * Add support for another type of segments
45
+ * Add support for another cnab versions
46
+ * Refactor classes and mix headers and trailers
39
47
 
40
48
  ## Mantainers
41
49
  [@plribeiro3000](https://github.com/plribeiro3000)
@@ -1,6 +1,8 @@
1
1
  module Cnab
2
2
  class Definition
3
3
  def initialize(version)
4
+ raise Exceptions::VersionNotImplemented unless File.directory?("lib/cnab/versions/#{version}")
5
+
4
6
  @header_arquivo = Definitions::HeaderArquivo.new(version)
5
7
  @header_lote = Definitions::HeaderLote.new(version)
6
8
  @segmento_t = Definitions::SegmentoT.new(version)
@@ -3,5 +3,6 @@ module Cnab
3
3
  autoload :NoFileGiven, 'cnab/exceptions/no_file_given'
4
4
  autoload :SegmentNotImplemented, 'cnab/exceptions/segment_not_implemented'
5
5
  autoload :LineNotParseable, 'cnab/exceptions/line_not_parseable'
6
+ autoload :VersionNotImplemented, 'cnab/exceptions/version_not_implemented'
6
7
  end
7
8
  end
@@ -0,0 +1,9 @@
1
+ module Cnab
2
+ module Exceptions
3
+ class VersionNotImplemented < StandardError
4
+ def self.initialize
5
+ super("This Version is not implemented!")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Cnab
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -6,10 +6,10 @@ qtd_registros: 17..22
6
6
  qtd_titulos_simples: 23..28
7
7
  valor_titulos_simples: 29..45
8
8
  qtd_titulos_vinculada: 46..51
9
- valor_titulos_simples: 52..68
9
+ valor_titulos_vinculada: 52..68
10
10
  qtd_titulos_caucionada: 69..74
11
11
  valor_titulos_caucionada: 75..91
12
12
  qtd_titulos_descontada: 92..97
13
13
  valor_titulos_descontada: 98..114
14
14
  num_aviso: 115..122
15
- res_cnab3: 123..239
15
+ res_cnab1: 123..239
@@ -0,0 +1,17 @@
1
+ banco: 0..2
2
+ lote: 3..6
3
+ registro: 7..7
4
+ res_banco1: 8..15
5
+ tipo_empresa: 16..16
6
+ num_empresa: 17..31
7
+ cod_transmissao: 32..46
8
+ res_banco2: 47..71
9
+ nome_empresa: 72..101
10
+ nome_banco: 102..131
11
+ res_banco3: 132..141
12
+ cod_retorno: 142..142
13
+ data_geracao_arq: 143..150
14
+ res_banco4: 151..156
15
+ sequencia: 157..162
16
+ versao: 163..165
17
+ res_banco5: 166..239
@@ -0,0 +1,19 @@
1
+ banco: 0..2
2
+ lote: 3..6
3
+ registro: 7..7
4
+ tipo_operacao: 8..8
5
+ tipo_servico: 9..10
6
+ res_banco1: 11..12
7
+ layout_lote: 13..15
8
+ res_banco2: 16..16
9
+ tipo_empresa: 17..17
10
+ num_empresa: 18..32
11
+ res_banco3: 33..52
12
+ cod_transmissao: 53..67
13
+ res_banco4: 68..72
14
+ nome_empresa: 73..102
15
+ informacao1: 103..142
16
+ informacao2: 143..182
17
+ numero_remessa: 183..190
18
+ data_gravacao: 191..198
19
+ res_banco5: 199..239
@@ -0,0 +1,29 @@
1
+ banco: 0..2
2
+ lote: 3..6
3
+ tipo_registro: 7..7
4
+ num_registro: 8..12
5
+ segmento: 13..13
6
+ res_banco1: 14..14
7
+ cod_movimentacao: 15..16
8
+ agencia: 17..20
9
+ dv_agencia: 21..21
10
+ conta_corrente: 22..30
11
+ dv_conta: 31..31
12
+ res_banco1: 32..39
13
+ id_titulo: 40..52
14
+ carteira: 53..53
15
+ doc_cobranca: 54..68
16
+ vencimento: 69..76
17
+ valor_titulo: 77..91
18
+ banco_recebimento: 92..94
19
+ ag_recebimento: 95..98
20
+ dv_ag_recebimento: 99..99
21
+ id_titulo_empresa: 100..124
22
+ cod_moeda: 125..126
23
+ tipo_inscricao: 127..127
24
+ num_inscricao: 128..142
25
+ nome: 143..182
26
+ conta_cobranca: 183..192
27
+ valor_tarifa: 193..207
28
+ identificacao: 208..217
29
+ res_banco2: 218..239
@@ -0,0 +1,23 @@
1
+ banco: 0..2
2
+ lote: 3..6
3
+ tipo_registro: 7..7
4
+ num_registro: 8..12
5
+ segmento: 13..13
6
+ res_banco1: 14..14
7
+ cod_movimentacao: 15..16
8
+ acrescimos: 17..31
9
+ valor_desconto: 32..46
10
+ valor_abatimento: 47..61
11
+ valor_iof: 62..76
12
+ valor_pago: 77..91
13
+ valor_liquido: 92..106
14
+ outras_despesas: 107..121
15
+ outros_creditos: 122..136
16
+ data_ocorrencia: 137..144
17
+ data_credito: 145..152
18
+ cod_ocorrencia_sacado: 153..156
19
+ data_ocorrencia_sacado: 157..164
20
+ valor_ocorrencia_sacado: 165..179
21
+ compl_ocorrencia_sacado: 180..209
22
+ cod_banco: 210..212
23
+ res_banco2: 213..239
@@ -0,0 +1,7 @@
1
+ banco: 0..2
2
+ lote: 3..6
3
+ registro: 7..7
4
+ res_banco1: 8..16
5
+ qtd_lotes: 17..22
6
+ qtd_registros: 23..28
7
+ res_banco1: 29..239
@@ -0,0 +1,15 @@
1
+ banco: 0..2
2
+ lote: 3..6
3
+ registro: 7..7
4
+ res_banco1: 8..16
5
+ qtd_registros: 17..22
6
+ qtd_titulos_simples: 23..28
7
+ valor_titulos_simples: 29..45
8
+ qtd_titulos_vinculada: 46..51
9
+ valor_titulos_vinculada: 52..68
10
+ qtd_titulos_caucionada: 69..74
11
+ valor_titulos_caucionada: 75..91
12
+ qtd_titulos_descontada: 92..97
13
+ valor_titulos_descontada: 98..114
14
+ num_aviso: 115..122
15
+ res_banco1: 123..239
@@ -2,28 +2,36 @@ require 'spec_helper'
2
2
 
3
3
  describe Cnab::Definition do
4
4
  describe "#initialize" do
5
- it "should initialize a header_arquivo instance" do
6
- Cnab::Definition.new('08.7').header_arquivo.should be_an_instance_of(Cnab::Definitions::HeaderArquivo)
5
+ context "with a non existent version" do
6
+ it "should raise and error" do
7
+ lambda { Cnab::Definition.new("wrong") }.should raise_error(Cnab::Exceptions::VersionNotImplemented)
8
+ end
7
9
  end
8
10
 
9
- it "should initialize a header_lote instance" do
10
- Cnab::Definition.new('08.7').header_lote.should be_an_instance_of(Cnab::Definitions::HeaderLote)
11
- end
11
+ context "with an existent version" do
12
+ it "should initialize a header_arquivo instance" do
13
+ Cnab::Definition.new('08.7').header_arquivo.should be_an_instance_of(Cnab::Definitions::HeaderArquivo)
14
+ end
12
15
 
13
- it "should initialize a segmento_t instance" do
14
- Cnab::Definition.new('08.7').segmento_t.should be_an_instance_of(Cnab::Definitions::SegmentoT)
15
- end
16
+ it "should initialize a header_lote instance" do
17
+ Cnab::Definition.new('08.7').header_lote.should be_an_instance_of(Cnab::Definitions::HeaderLote)
18
+ end
16
19
 
17
- it "should initialize a segmento_u instance" do
18
- Cnab::Definition.new('08.7').segmento_u.should be_an_instance_of(Cnab::Definitions::SegmentoU)
19
- end
20
+ it "should initialize a segmento_t instance" do
21
+ Cnab::Definition.new('08.7').segmento_t.should be_an_instance_of(Cnab::Definitions::SegmentoT)
22
+ end
20
23
 
21
- it "should initialize a trailer_lote instance" do
22
- Cnab::Definition.new('08.7').trailer_lote.should be_an_instance_of(Cnab::Definitions::TrailerLote)
23
- end
24
+ it "should initialize a segmento_u instance" do
25
+ Cnab::Definition.new('08.7').segmento_u.should be_an_instance_of(Cnab::Definitions::SegmentoU)
26
+ end
27
+
28
+ it "should initialize a trailer_lote instance" do
29
+ Cnab::Definition.new('08.7').trailer_lote.should be_an_instance_of(Cnab::Definitions::TrailerLote)
30
+ end
24
31
 
25
- it "should initialize a trailer_arquivo instance" do
26
- Cnab::Definition.new('08.7').trailer_arquivo.should be_an_instance_of(Cnab::Definitions::TrailerArquivo)
32
+ it "should initialize a trailer_arquivo instance" do
33
+ Cnab::Definition.new('08.7').trailer_arquivo.should be_an_instance_of(Cnab::Definitions::TrailerArquivo)
34
+ end
27
35
  end
28
36
  end
29
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-01 00:00:00.000000000 Z
13
+ date: 2013-04-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -94,6 +94,7 @@ files:
94
94
  - lib/cnab/exceptions/line_not_parseable.rb
95
95
  - lib/cnab/exceptions/no_file_given.rb
96
96
  - lib/cnab/exceptions/segment_not_implemented.rb
97
+ - lib/cnab/exceptions/version_not_implemented.rb
97
98
  - lib/cnab/header_arquivo.rb
98
99
  - lib/cnab/header_lote.rb
99
100
  - lib/cnab/header_lote/cobranca.rb
@@ -109,6 +110,12 @@ files:
109
110
  - lib/cnab/versions/08.7/segmento_u.yml
110
111
  - lib/cnab/versions/08.7/trailer_arquivo.yml
111
112
  - lib/cnab/versions/08.7/trailer_lote.yml
113
+ - lib/cnab/versions/santander/header_arquivo.yml
114
+ - lib/cnab/versions/santander/header_lote.yml
115
+ - lib/cnab/versions/santander/segmento_t.yml
116
+ - lib/cnab/versions/santander/segmento_u.yml
117
+ - lib/cnab/versions/santander/trailer_arquivo.yml
118
+ - lib/cnab/versions/santander/trailer_lote.yml
112
119
  - spec/cnab.txt
113
120
  - spec/cnab/definition_spec.rb
114
121
  - spec/cnab/definitions/header_arquivo_spec.rb
@@ -141,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
148
  version: '0'
142
149
  segments:
143
150
  - 0
144
- hash: 3361106697882866932
151
+ hash: -501080544786458903
145
152
  required_rubygems_version: !ruby/object:Gem::Requirement
146
153
  none: false
147
154
  requirements:
@@ -150,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
157
  version: '0'
151
158
  segments:
152
159
  - 0
153
- hash: 3361106697882866932
160
+ hash: -501080544786458903
154
161
  requirements: []
155
162
  rubyforge_project:
156
163
  rubygems_version: 1.8.25