cnab240 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/cnab240.gemspec +10 -12
- data/lib/cnab240.rb +108 -91
- data/lib/cnab240/arquivo/arquivo.rb +6 -9
- data/lib/cnab240/arquivo/builder.rb +111 -90
- data/lib/cnab240/arquivo/estrutura.rb +161 -99
- data/lib/cnab240/arquivo/v40/header.rb +27 -29
- data/lib/cnab240/arquivo/v40/trailer.rb +8 -10
- data/lib/cnab240/arquivo/v60/header.rb +38 -0
- data/lib/cnab240/arquivo/v60/trailer.rb +17 -0
- data/lib/cnab240/arquivo/v80/header.rb +23 -26
- data/lib/cnab240/arquivo/v80/trailer.rb +8 -9
- data/lib/cnab240/arquivo/v81/header.rb +37 -0
- data/lib/cnab240/arquivo/v81/trailer.rb +17 -0
- data/lib/cnab240/arquivo/v83/header.rb +25 -26
- data/lib/cnab240/arquivo/v83/trailer.rb +9 -9
- data/lib/cnab240/arquivo/v86/header.rb +25 -26
- data/lib/cnab240/arquivo/v86/trailer.rb +9 -10
- data/lib/cnab240/arquivo/v87/header.rb +25 -26
- data/lib/cnab240/arquivo/v87/trailer.rb +9 -10
- data/lib/cnab240/ext/attribute_accessors.rb +4 -4
- data/lib/cnab240/ext/bindata.rb +4 -4
- data/lib/cnab240/ext/default_mixin.rb +2 -4
- data/lib/cnab240/ext/filler.rb +1 -3
- data/lib/cnab240/ext/lstring.rb +9 -10
- data/lib/cnab240/ext/segmento_mixin.rb +1 -3
- data/lib/cnab240/helper/boleto_bancoob.rb +60 -0
- data/lib/cnab240/helper/helper.rb +1 -1
- data/lib/cnab240/helper/pagamento_bb.rb +7 -9
- data/lib/cnab240/helper/pagamento_bradesco.rb +6 -8
- data/lib/cnab240/helper/pagamento_itau.rb +6 -8
- data/lib/cnab240/helper/transferencia_citibank.rb +56 -0
- data/lib/cnab240/helper/{pagamento_sicoob.rb → transferencia_sicoob.rb} +8 -15
- data/lib/cnab240/{arquivo/lote.rb → lote.rb} +29 -14
- data/lib/cnab240/lote/v40/boletos/header.rb +46 -0
- data/lib/cnab240/lote/v40/boletos/trailer.rb +29 -0
- data/lib/cnab240/pagamentos/v40/header.rb +30 -32
- data/lib/cnab240/pagamentos/v40/trailer.rb +10 -11
- data/lib/cnab240/pagamentos/v60/header.rb +43 -0
- data/lib/cnab240/pagamentos/v60/trailer.rb +17 -0
- data/lib/cnab240/pagamentos/v80/header.rb +35 -37
- data/lib/cnab240/pagamentos/v80/trailer.rb +10 -11
- data/lib/cnab240/pagamentos/v83/header.rb +33 -35
- data/lib/cnab240/pagamentos/v83/trailer.rb +11 -12
- data/lib/cnab240/pagamentos/v86/header.rb +34 -36
- data/lib/cnab240/pagamentos/v86/titulos/header.rb +28 -30
- data/lib/cnab240/pagamentos/v86/titulos/trailer.rb +11 -12
- data/lib/cnab240/pagamentos/v86/trailer.rb +11 -12
- data/lib/cnab240/pagamentos/v86/tributos/header.rb +35 -37
- data/lib/cnab240/pagamentos/v86/tributos/trailer.rb +9 -10
- data/lib/cnab240/pagamentos/v87/header.rb +34 -36
- data/lib/cnab240/pagamentos/v87/titulos/header.rb +28 -30
- data/lib/cnab240/pagamentos/v87/titulos/trailer.rb +11 -12
- data/lib/cnab240/pagamentos/v87/trailer.rb +11 -12
- data/lib/cnab240/pagamentos/v87/tributos/header.rb +35 -37
- data/lib/cnab240/pagamentos/v87/tributos/trailer.rb +9 -10
- data/lib/cnab240/segmentos/v40/segmento_a.rb +40 -41
- data/lib/cnab240/segmentos/v60/segmento_a.rb +43 -0
- data/lib/cnab240/segmentos/v60/segmento_b.rb +38 -0
- data/lib/cnab240/segmentos/v60/segmento_j.rb +32 -0
- data/lib/cnab240/segmentos/v80/agencia_itau.rb +8 -9
- data/lib/cnab240/segmentos/v80/agencia_outros.rb +6 -7
- data/lib/cnab240/segmentos/v80/segmento_a.rb +30 -32
- data/lib/cnab240/segmentos/v81/segmento_p.rb +79 -0
- data/lib/cnab240/segmentos/v81/segmento_q.rb +36 -0
- data/lib/cnab240/segmentos/v81/segmento_r.rb +49 -0
- data/lib/cnab240/segmentos/v81/segmento_s.rb +37 -0
- data/lib/cnab240/segmentos/v83/segmento_a.rb +35 -36
- data/lib/cnab240/segmentos/v83/segmento_b.rb +33 -34
- data/lib/cnab240/segmentos/v83/segmento_j.rb +22 -23
- data/lib/cnab240/segmentos/v83/segmento_z.rb +10 -11
- data/lib/cnab240/segmentos/v86/segmento_a.rb +37 -38
- data/lib/cnab240/segmentos/v86/segmento_b.rb +33 -34
- data/lib/cnab240/segmentos/v86/segmento_c.rb +19 -20
- data/lib/cnab240/segmentos/v86/segmento_j.rb +22 -23
- data/lib/cnab240/segmentos/v86/segmento_j52.rb +19 -20
- data/lib/cnab240/segmentos/v86/segmento_n.rb +17 -18
- data/lib/cnab240/segmentos/v86/segmento_n1.rb +10 -11
- data/lib/cnab240/segmentos/v86/segmento_n2.rb +12 -13
- data/lib/cnab240/segmentos/v86/segmento_n3.rb +12 -13
- data/lib/cnab240/segmentos/v86/segmento_n4.rb +14 -15
- data/lib/cnab240/segmentos/v86/segmento_n5.rb +12 -13
- data/lib/cnab240/segmentos/v86/segmento_n6.rb +12 -13
- data/lib/cnab240/segmentos/v86/segmento_n7.rb +13 -14
- data/lib/cnab240/segmentos/v86/segmento_n8.rb +12 -14
- data/lib/cnab240/segmentos/v86/segmento_o.rb +17 -18
- data/lib/cnab240/segmentos/v86/segmento_w.rb +12 -13
- data/lib/cnab240/segmentos/v86/segmento_w1.rb +9 -10
- data/lib/cnab240/segmentos/v86/segmento_z.rb +10 -11
- data/lib/cnab240/segmentos/v87/segmento_a.rb +37 -38
- data/lib/cnab240/segmentos/v87/segmento_b.rb +33 -34
- data/lib/cnab240/segmentos/v87/segmento_c.rb +19 -20
- data/lib/cnab240/segmentos/v87/segmento_j.rb +22 -23
- data/lib/cnab240/segmentos/v87/segmento_j52.rb +19 -20
- data/lib/cnab240/segmentos/v87/segmento_n.rb +17 -18
- data/lib/cnab240/segmentos/v87/segmento_n1.rb +10 -11
- data/lib/cnab240/segmentos/v87/segmento_n2.rb +12 -13
- data/lib/cnab240/segmentos/v87/segmento_n3.rb +12 -13
- data/lib/cnab240/segmentos/v87/segmento_n4.rb +14 -15
- data/lib/cnab240/segmentos/v87/segmento_n5.rb +12 -13
- data/lib/cnab240/segmentos/v87/segmento_n6.rb +12 -13
- data/lib/cnab240/segmentos/v87/segmento_n7.rb +13 -14
- data/lib/cnab240/segmentos/v87/segmento_n8.rb +12 -14
- data/lib/cnab240/segmentos/v87/segmento_o.rb +17 -18
- data/lib/cnab240/segmentos/v87/segmento_w.rb +12 -13
- data/lib/cnab240/segmentos/v87/segmento_w1.rb +9 -10
- data/lib/cnab240/segmentos/v87/segmento_z.rb +10 -11
- data/lib/cnab240/version.rb +1 -1
- metadata +30 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e20d6063cf9ddd42d84cc9c30d79f46f831c3a1
|
4
|
+
data.tar.gz: 8c2287101ec6e0f112d62cc428ca6b4d554561cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 159d6fc3f14d3936e7c10cf014a645a1da3e2c931388d53c99f4b9fa86c54f0eaf73c411408093af279a68ee780bfb5b046b50ffcdef5ef9d7c9fae626a432e8
|
7
|
+
data.tar.gz: b1c769c4088dfce5c3151d47a465d8bbb8f1864f31e1150f4dd7ceb243dd43b3c8258a3bce06ec9db21da1c17e557f6b1d6f6f1747ba337619a7ec8e5523a5e0
|
data/Rakefile
CHANGED
data/cnab240.gemspec
CHANGED
@@ -2,22 +2,20 @@
|
|
2
2
|
require File.expand_path('../lib/cnab240/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.
|
6
|
-
gem.add_development_dependency "debugger"
|
7
|
-
gem.add_dependency "bindata"
|
5
|
+
gem.add_dependency 'bindata', '~> 2.2.0'
|
8
6
|
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.description =
|
12
|
-
gem.summary =
|
13
|
-
gem.homepage =
|
7
|
+
gem.authors = ['Eduardo Mourao (RIP)', 'Kivanio Barbosa']
|
8
|
+
gem.email = ['kivanio@gmail.com']
|
9
|
+
gem.description = 'Formato CNAB 240.'
|
10
|
+
gem.summary = 'Formato CNAB 240.'
|
11
|
+
gem.homepage = 'https://github.com/eduardordm/cnab240'
|
14
12
|
|
15
|
-
gem.rubyforge_project =
|
13
|
+
gem.rubyforge_project = 'cnab240'
|
16
14
|
|
17
15
|
gem.files = Dir.glob('lib/**/*') + ['Rakefile'] + ['cnab240.gemspec']
|
18
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
19
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
-
gem.name =
|
21
|
-
gem.require_paths = [
|
18
|
+
gem.name = 'cnab240'
|
19
|
+
gem.require_paths = ['lib']
|
22
20
|
gem.version = Cnab240::VERSION
|
23
21
|
end
|
data/lib/cnab240.rb
CHANGED
@@ -1,109 +1,127 @@
|
|
1
|
-
require
|
1
|
+
require 'cnab240/version'
|
2
2
|
|
3
3
|
require 'bindata'
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
5
|
+
require 'cnab240/ext/attribute_accessors'
|
6
|
+
require 'cnab240/ext/bindata'
|
7
|
+
require 'cnab240/ext/lstring'
|
8
|
+
require 'cnab240/ext/default_mixin'
|
9
|
+
require 'cnab240/ext/segmento_mixin'
|
10
|
+
require 'cnab240/ext/filler'
|
11
11
|
|
12
|
-
require
|
12
|
+
require 'cnab240/lote'
|
13
|
+
require 'cnab240/lote/v40/boletos/header'
|
14
|
+
require 'cnab240/lote/v40/boletos/trailer'
|
13
15
|
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
require
|
48
|
-
require
|
49
|
-
require
|
50
|
-
require
|
51
|
-
require
|
52
|
-
require
|
53
|
-
require
|
54
|
-
require
|
55
|
-
require
|
56
|
-
require
|
57
|
-
require
|
16
|
+
require 'cnab240/segmentos/v40/segmento_a'
|
17
|
+
require 'cnab240/segmentos/v60/segmento_a'
|
18
|
+
require 'cnab240/segmentos/v60/segmento_b'
|
19
|
+
require 'cnab240/segmentos/v60/segmento_j'
|
20
|
+
require 'cnab240/segmentos/v80/agencia_itau'
|
21
|
+
require 'cnab240/segmentos/v80/agencia_outros'
|
22
|
+
require 'cnab240/segmentos/v80/segmento_a'
|
23
|
+
require 'cnab240/segmentos/v81/segmento_p'
|
24
|
+
require 'cnab240/segmentos/v81/segmento_q'
|
25
|
+
require 'cnab240/segmentos/v81/segmento_r'
|
26
|
+
require 'cnab240/segmentos/v81/segmento_s'
|
27
|
+
require 'cnab240/segmentos/v83/segmento_a'
|
28
|
+
require 'cnab240/segmentos/v83/segmento_b'
|
29
|
+
require 'cnab240/segmentos/v83/segmento_z'
|
30
|
+
require 'cnab240/segmentos/v83/segmento_j'
|
31
|
+
require 'cnab240/segmentos/v86/segmento_a'
|
32
|
+
require 'cnab240/segmentos/v86/segmento_b'
|
33
|
+
require 'cnab240/segmentos/v86/segmento_c'
|
34
|
+
require 'cnab240/segmentos/v86/segmento_j'
|
35
|
+
require 'cnab240/segmentos/v86/segmento_j52'
|
36
|
+
require 'cnab240/segmentos/v86/segmento_o'
|
37
|
+
require 'cnab240/segmentos/v86/segmento_n8'
|
38
|
+
require 'cnab240/segmentos/v86/segmento_n7'
|
39
|
+
require 'cnab240/segmentos/v86/segmento_n6'
|
40
|
+
require 'cnab240/segmentos/v86/segmento_n5'
|
41
|
+
require 'cnab240/segmentos/v86/segmento_n4'
|
42
|
+
require 'cnab240/segmentos/v86/segmento_n3'
|
43
|
+
require 'cnab240/segmentos/v86/segmento_n2'
|
44
|
+
require 'cnab240/segmentos/v86/segmento_n1'
|
45
|
+
require 'cnab240/segmentos/v86/segmento_n'
|
46
|
+
require 'cnab240/segmentos/v86/segmento_w1'
|
47
|
+
require 'cnab240/segmentos/v86/segmento_w'
|
48
|
+
require 'cnab240/segmentos/v86/segmento_z'
|
49
|
+
require 'cnab240/segmentos/v87/segmento_a'
|
50
|
+
require 'cnab240/segmentos/v87/segmento_b'
|
51
|
+
require 'cnab240/segmentos/v87/segmento_c'
|
52
|
+
require 'cnab240/segmentos/v87/segmento_j'
|
53
|
+
require 'cnab240/segmentos/v87/segmento_j52'
|
54
|
+
require 'cnab240/segmentos/v87/segmento_o'
|
55
|
+
require 'cnab240/segmentos/v87/segmento_n8'
|
56
|
+
require 'cnab240/segmentos/v87/segmento_n7'
|
57
|
+
require 'cnab240/segmentos/v87/segmento_n6'
|
58
|
+
require 'cnab240/segmentos/v87/segmento_n5'
|
59
|
+
require 'cnab240/segmentos/v87/segmento_n4'
|
60
|
+
require 'cnab240/segmentos/v87/segmento_n3'
|
61
|
+
require 'cnab240/segmentos/v87/segmento_n2'
|
62
|
+
require 'cnab240/segmentos/v87/segmento_n1'
|
63
|
+
require 'cnab240/segmentos/v87/segmento_n'
|
64
|
+
require 'cnab240/segmentos/v87/segmento_w1'
|
65
|
+
require 'cnab240/segmentos/v87/segmento_w'
|
66
|
+
require 'cnab240/segmentos/v87/segmento_z'
|
58
67
|
|
59
|
-
require
|
68
|
+
require 'cnab240/arquivo/arquivo'
|
60
69
|
|
61
|
-
require
|
62
|
-
require
|
63
|
-
require
|
64
|
-
require
|
65
|
-
require
|
66
|
-
require
|
67
|
-
require
|
68
|
-
require
|
69
|
-
require
|
70
|
-
require
|
70
|
+
require 'cnab240/arquivo/v80/header'
|
71
|
+
require 'cnab240/arquivo/v80/trailer'
|
72
|
+
require 'cnab240/arquivo/v81/header'
|
73
|
+
require 'cnab240/arquivo/v81/trailer'
|
74
|
+
require 'cnab240/arquivo/v83/header'
|
75
|
+
require 'cnab240/arquivo/v83/trailer'
|
76
|
+
require 'cnab240/arquivo/v86/header'
|
77
|
+
require 'cnab240/arquivo/v86/trailer'
|
78
|
+
require 'cnab240/arquivo/v40/header'
|
79
|
+
require 'cnab240/arquivo/v40/trailer'
|
80
|
+
require 'cnab240/arquivo/v87/header'
|
81
|
+
require 'cnab240/arquivo/v87/trailer'
|
82
|
+
require 'cnab240/arquivo/v60/header'
|
83
|
+
require 'cnab240/arquivo/v60/trailer'
|
71
84
|
|
72
|
-
require
|
73
|
-
require
|
74
|
-
require
|
75
|
-
require
|
76
|
-
require
|
77
|
-
require
|
78
|
-
require
|
79
|
-
require
|
80
|
-
require
|
81
|
-
require
|
82
|
-
require
|
83
|
-
require
|
84
|
-
require
|
85
|
-
require
|
86
|
-
require
|
87
|
-
require
|
88
|
-
require
|
89
|
-
require
|
85
|
+
require 'cnab240/pagamentos/v80/header'
|
86
|
+
require 'cnab240/pagamentos/v80/trailer'
|
87
|
+
require 'cnab240/pagamentos/v83/header'
|
88
|
+
require 'cnab240/pagamentos/v83/trailer'
|
89
|
+
require 'cnab240/pagamentos/v86/header'
|
90
|
+
require 'cnab240/pagamentos/v86/trailer'
|
91
|
+
require 'cnab240/pagamentos/v86/titulos/header'
|
92
|
+
require 'cnab240/pagamentos/v86/titulos/trailer'
|
93
|
+
require 'cnab240/pagamentos/v86/tributos/header'
|
94
|
+
require 'cnab240/pagamentos/v86/tributos/trailer'
|
95
|
+
require 'cnab240/pagamentos/v87/header'
|
96
|
+
require 'cnab240/pagamentos/v87/trailer'
|
97
|
+
require 'cnab240/pagamentos/v87/titulos/header'
|
98
|
+
require 'cnab240/pagamentos/v87/titulos/trailer'
|
99
|
+
require 'cnab240/pagamentos/v87/tributos/header'
|
100
|
+
require 'cnab240/pagamentos/v87/tributos/trailer'
|
101
|
+
require 'cnab240/pagamentos/v40/header'
|
102
|
+
require 'cnab240/pagamentos/v40/trailer'
|
103
|
+
require 'cnab240/pagamentos/v60/header'
|
104
|
+
require 'cnab240/pagamentos/v60/trailer'
|
90
105
|
|
91
|
-
require
|
92
|
-
require
|
106
|
+
require 'cnab240/arquivo/estrutura'
|
107
|
+
require 'cnab240/arquivo/builder'
|
93
108
|
|
94
|
-
require
|
95
|
-
require
|
96
|
-
require
|
97
|
-
require
|
98
|
-
require "cnab240/helper/pagamento_sicoob"
|
109
|
+
require 'cnab240/helper/helper'
|
110
|
+
require 'cnab240/helper/pagamento_itau'
|
111
|
+
require 'cnab240/helper/pagamento_bradesco'
|
112
|
+
require 'cnab240/helper/pagamento_bb'
|
99
113
|
|
100
|
-
|
114
|
+
require 'cnab240/helper/transferencia_sicoob'
|
115
|
+
require 'cnab240/helper/transferencia_citibank'
|
116
|
+
|
117
|
+
require 'cnab240/helper/boleto_bancoob'
|
101
118
|
|
119
|
+
module Cnab240
|
102
120
|
mod_attr_accessor :defaults
|
103
121
|
@@defaults = {}
|
104
122
|
|
105
123
|
mod_attr_accessor :fallback
|
106
|
-
@@fallback =
|
124
|
+
@@fallback = 'V86'
|
107
125
|
|
108
126
|
mod_attr_accessor :auto_fill_enabled
|
109
127
|
@@auto_fill_enabled = true
|
@@ -117,5 +135,4 @@ module Cnab240
|
|
117
135
|
def self.setup
|
118
136
|
yield self
|
119
137
|
end
|
120
|
-
|
121
138
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module Cnab240::Arquivo
|
2
2
|
class Arquivo
|
3
|
-
|
4
3
|
attr_accessor :header
|
5
4
|
attr_accessor :lotes
|
6
5
|
attr_accessor :trailer
|
7
6
|
attr_accessor :versao
|
8
7
|
|
9
|
-
def initialize(versao =
|
8
|
+
def initialize(versao = 'V86')
|
10
9
|
@versao = versao
|
11
10
|
@header = eval("Cnab240::#{versao}::Arquivo::Header").new
|
12
11
|
@trailer = eval("Cnab240::#{versao}::Arquivo::Trailer").new
|
@@ -14,7 +13,7 @@ module Cnab240::Arquivo
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def linhas
|
17
|
-
|
16
|
+
auto_fill if Cnab240.auto_fill_enabled
|
18
17
|
a = []
|
19
18
|
a << @header.linha
|
20
19
|
@lotes.each do |lote|
|
@@ -32,9 +31,9 @@ module Cnab240::Arquivo
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def string
|
35
|
-
linhas.join("\
|
34
|
+
linhas.join("\n") << "\n"
|
36
35
|
end
|
37
|
-
|
36
|
+
|
38
37
|
# Writes +Cnab240::Arquivo::Arquivo+ contents into a +File+, overwriting its current contents.
|
39
38
|
#
|
40
39
|
# @example Save contents to a file.
|
@@ -46,9 +45,9 @@ module Cnab240::Arquivo
|
|
46
45
|
#
|
47
46
|
# @since 0.0.20
|
48
47
|
def save_to_file(filename)
|
49
|
-
File.open(filename, 'w'){|f| f.write(string)}
|
48
|
+
File.open(filename, 'w') { |f| f.write(string) }
|
50
49
|
end
|
51
|
-
|
50
|
+
|
52
51
|
# Loads contents from a +File+ into +Cnab240::Arquivo::Arquivo+ instances.
|
53
52
|
#
|
54
53
|
# @example Load contents from a file.
|
@@ -84,7 +83,5 @@ module Cnab240::Arquivo
|
|
84
83
|
qtd_registros += 2 # header e trailer de arquivo
|
85
84
|
trailer.totais_qtde_registros = qtd_registros.to_s
|
86
85
|
end
|
87
|
-
|
88
86
|
end
|
89
|
-
|
90
87
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Cnab240
|
2
2
|
class Builder
|
3
|
-
|
4
3
|
HEADER_ARQUIVO = '0'
|
5
4
|
HEADER_LOTE = '1'
|
6
5
|
INICIAIS_LOTE = '2'
|
@@ -27,29 +26,29 @@ module Cnab240
|
|
27
26
|
check_line_encoding line, ++line_number
|
28
27
|
case line[RANGE_TIPO_REGISTRO]
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
when HEADER_ARQUIVO
|
30
|
+
find_header_arquivo line, line_number
|
32
31
|
|
33
|
-
|
34
|
-
|
32
|
+
when HEADER_LOTE
|
33
|
+
find_header_lote line, line_number
|
35
34
|
|
36
|
-
|
37
|
-
|
35
|
+
when INICIAIS_LOTE
|
36
|
+
fail NotImplementedError.new('Tipo de registro nao suportado')
|
38
37
|
|
39
|
-
|
40
|
-
|
38
|
+
when DETALHE
|
39
|
+
find_segmento line, line_number
|
41
40
|
|
42
|
-
|
43
|
-
|
41
|
+
when FINAIS_LOTE
|
42
|
+
fail NotImplementedError.new('Tipo de registro not implemented')
|
44
43
|
|
45
|
-
|
46
|
-
|
44
|
+
when TRAILER_LOTE
|
45
|
+
arquivos.last.lotes.last.trailer.read(line)
|
47
46
|
|
48
|
-
|
49
|
-
|
47
|
+
when TRAILER_ARQUIVO
|
48
|
+
arquivos.last.trailer.read(line)
|
50
49
|
|
51
|
-
|
52
|
-
|
50
|
+
else
|
51
|
+
fail "Invalid tipo de registro: #{line[RANGE_TIPO_REGISTRO]} at line #{line_number} \n\t Line: [#{line}]"
|
53
52
|
end
|
54
53
|
end
|
55
54
|
arquivos
|
@@ -58,107 +57,129 @@ module Cnab240
|
|
58
57
|
private
|
59
58
|
|
60
59
|
def check_line_encoding(line, line_number = -1)
|
61
|
-
line = line.force_encoding(
|
62
|
-
line.gsub!("\r",
|
63
|
-
line.gsub!("\n",
|
64
|
-
|
60
|
+
line = line.force_encoding('US-ASCII').encode('UTF-8', invalid: :replace) if line.respond_to?(:force_encoding)
|
61
|
+
line.gsub!("\r", '')
|
62
|
+
line.gsub!("\n", '')
|
63
|
+
fail "Invalid line length: #{line.length} expected 240 at line number #{line_number}\n\t Line: [#{line}]" unless line.length == 240
|
65
64
|
line
|
66
65
|
end
|
67
66
|
|
68
67
|
def find_header_arquivo(line, line_number = -1)
|
69
68
|
arquivos << Cnab240::Arquivo::Arquivo.new
|
70
69
|
case line[RANGE_LAYOUT_ARQUIVO]
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
70
|
+
when '087'
|
71
|
+
arquivos.last.versao = 'V87'
|
72
|
+
arquivos.last.header = Cnab240::V87::Arquivo::Header.read(line)
|
73
|
+
when '085'
|
74
|
+
arquivos.last.versao = 'V86'
|
75
|
+
arquivos.last.header = Cnab240::V86::Arquivo::Header.read(line)
|
76
|
+
when '081'
|
77
|
+
arquivos.last.versao = 'V81'
|
78
|
+
arquivos.last.header = Cnab240::V81::Arquivo::Header.read(line)
|
79
|
+
when '040'
|
80
|
+
arquivos.last.versao = 'V40'
|
81
|
+
arquivos.last.header = Cnab240::V40::Arquivo::Header.read(line)
|
82
|
+
when '060'
|
83
|
+
arquivos.last.versao = 'V60'
|
84
|
+
arquivos.last.header = Cnab240::V60::Arquivo::Header.read(line)
|
85
|
+
when '000' # possivelmente V80 do itau
|
86
|
+
if line[14..16] == '080'
|
87
|
+
arquivos.last.versao = 'V80'
|
88
|
+
arquivos.last.header = Cnab240::V80::Arquivo::Header.read(line)
|
89
89
|
else
|
90
|
-
|
90
|
+
fail "Versao de arquivo nao suportado: #{line[RANGE_LAYOUT_ARQUIVO]} na linha #{line_number}" if Cnab240.fallback == false
|
91
91
|
arquivos.last.versao = 'V86'
|
92
92
|
arquivos.last.header = Cnab240::V86::Arquivo::Header.read(line)
|
93
|
+
end
|
94
|
+
else
|
95
|
+
fail "Versao de arquivo nao suportado: #{line[RANGE_LAYOUT_ARQUIVO]} na linha #{line_number}" if Cnab240.fallback == false
|
96
|
+
arquivos.last.versao = 'V86'
|
97
|
+
arquivos.last.header = Cnab240::V86::Arquivo::Header.read(line)
|
93
98
|
end
|
94
99
|
end
|
95
100
|
|
96
101
|
def find_header_lote(line, line_number = -1)
|
97
102
|
case line[RANGE_HEADER_LOTE]
|
98
|
-
|
99
|
-
|
103
|
+
when '080'
|
104
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento, tipo: :none, versao: 'V80') do |l|
|
105
|
+
l.header = Cnab240::V80::Pagamentos::Header.read(line)
|
106
|
+
end
|
107
|
+
when '030'
|
108
|
+
case arquivos.last.versao
|
109
|
+
when 'V80'
|
110
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento, tipo: :none) do |l|
|
100
111
|
l.header = Cnab240::V80::Pagamentos::Header.read(line)
|
101
112
|
end
|
102
|
-
when '
|
103
|
-
|
104
|
-
|
105
|
-
arquivos.last.lotes << Cnab240::Lote.new(:operacao => :pagamento, :tipo => :none) do |l|
|
106
|
-
l.header = Cnab240::V80::Pagamentos::Header.read(line)
|
107
|
-
end
|
108
|
-
when 'V40'
|
109
|
-
arquivos.last.lotes << Cnab240::Lote.new(:operacao => :pagamento, :tipo => :none) do |l|
|
110
|
-
l.header = Cnab240::V40::Pagamentos::Header.read(line)
|
111
|
-
end
|
112
|
-
else
|
113
|
-
raise "Header de lote nao suportado para a versao de arquivo."
|
113
|
+
when 'V40'
|
114
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento, tipo: :none) do |l|
|
115
|
+
l.header = Cnab240::V40::Pagamentos::Header.read(line)
|
114
116
|
end
|
115
|
-
|
116
|
-
|
117
|
-
|
117
|
+
else
|
118
|
+
fail 'Header de lote nao suportado para a versao de arquivo.'
|
119
|
+
end
|
120
|
+
when '031'
|
121
|
+
case arquivos.last.versao
|
122
|
+
when 'V60'
|
123
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento, tipo: :none) do |l|
|
124
|
+
l.header = Cnab240::V60::Pagamentos::Header.read(line)
|
118
125
|
end
|
119
|
-
when '
|
120
|
-
arquivos.last.lotes << Cnab240::Lote.new(:
|
121
|
-
l.header = Cnab240::
|
126
|
+
when 'V83'
|
127
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento, tipo: :none) do |l|
|
128
|
+
l.header = Cnab240::V83::Pagamentos::Header.read(line)
|
122
129
|
end
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
130
|
+
else
|
131
|
+
fail 'Header de lote nao suportado para a versao de arquivo.'
|
132
|
+
end
|
133
|
+
when '045'
|
134
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento, tipo: :none) do |l|
|
135
|
+
l.header = Cnab240::V87::Pagamentos::Header.read(line)
|
136
|
+
end
|
137
|
+
when '044'
|
138
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento, tipo: :none) do |l|
|
139
|
+
l.header = Cnab240::V86::Pagamentos::Header.read(line)
|
140
|
+
end
|
141
|
+
when '040'
|
142
|
+
case arquivos.last.versao
|
143
|
+
when 'V80'
|
144
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento, tipo: :none) do |l|
|
145
|
+
l.header = Cnab240::V80::Pagamentos::Header.read(line)
|
146
|
+
end
|
147
|
+
when 'V81'
|
148
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :boleto, tipo: :none, versao: 'V81') do |l|
|
149
|
+
l.header = Cnab240::Lote::V40::Boletos::Header.read(line)
|
150
|
+
end
|
151
|
+
when 'V86'
|
152
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento_titulo_cobranca, tipo: :none) do |l|
|
153
|
+
l.header = Cnab240::V86::PagamentosTitulos::Header.read(line)
|
139
154
|
end
|
140
|
-
when '
|
141
|
-
arquivos.last.lotes << Cnab240::Lote.new(:
|
142
|
-
l.header = Cnab240::
|
155
|
+
when 'V87'
|
156
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento_titulo_cobranca, tipo: :none) do |l|
|
157
|
+
l.header = Cnab240::V87::PagamentosTitulos::Header.read(line)
|
143
158
|
end
|
144
159
|
else
|
145
|
-
|
160
|
+
fail 'Header de lote nao suportado para a versao de arquivo.'
|
161
|
+
end
|
162
|
+
when '011'
|
163
|
+
arquivos.last.lotes << Cnab240::Lote.new(operacao: :pagamento_titulo_tributos, tipo: :none) do |l|
|
164
|
+
l.header = Cnab240::V86::PagamentosTributos::Header.read(line)
|
165
|
+
end
|
166
|
+
else
|
167
|
+
fail "Tipo de lote nao suportado: #{line[RANGE_HEADER_LOTE]} na linha #{line_number}"
|
146
168
|
end
|
147
169
|
end
|
148
170
|
|
149
171
|
def find_segmento(line, line_number = -1)
|
150
|
-
|
172
|
+
fail "Invalid segmento de lote: #{line[RANGE_TIPO_OPERACAO_DETALHE]} at line #{line_number} in version #{arquivos.last.versao}" unless ESTRUTURA[arquivos.last.versao][:segmentos_implementados].include? line[RANGE_TIPO_OPERACAO_DETALHE].downcase.intern
|
151
173
|
case line[RANGE_TIPO_OPERACAO_DETALHE]
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
else
|
156
|
-
arquivos.last.lotes.last.read_segmento('J', line)
|
157
|
-
end
|
174
|
+
when 'J'
|
175
|
+
if line[17..18] == '52'
|
176
|
+
arquivos.last.lotes.last.read_segmento('J52', line)
|
158
177
|
else
|
159
|
-
arquivos.last.lotes.last.read_segmento(
|
178
|
+
arquivos.last.lotes.last.read_segmento('J', line)
|
179
|
+
end
|
180
|
+
else
|
181
|
+
arquivos.last.lotes.last.read_segmento(line[RANGE_TIPO_OPERACAO_DETALHE], line)
|
160
182
|
end
|
161
183
|
end
|
162
|
-
|
163
184
|
end
|
164
|
-
end
|
185
|
+
end
|