cnab240 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -5
- data/lib/cnab240/arquivo/lote.rb +57 -0
- data/lib/cnab240/core_ext/bindata.rb +1 -0
- data/lib/cnab240/pagamentos/header.rb +6 -0
- data/lib/cnab240/version.rb +1 -1
- data/lib/cnab240.rb +10 -1
- data/spec/arquivo/arquivo_spec.rb +4 -4
- data/spec/pagamentos/header_spec.rb +3 -5
- data/spec/pagamentos/lote_spec.rb +13 -5
- data/spec/pagamentos/trailer_spec.rb +3 -5
- metadata +4 -4
- data/lib/cnab240/pagamentos/lote.rb +0 -25
data/.travis.yml
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Cnab240
|
2
|
+
class Lote
|
3
|
+
attr_accessor :header
|
4
|
+
attr_accessor :segmentos
|
5
|
+
attr_accessor :trailer
|
6
|
+
attr_accessor :operacao
|
7
|
+
|
8
|
+
def initialize(op = nil)
|
9
|
+
@segmentos = {}
|
10
|
+
|
11
|
+
unless @operacao = op
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
15
|
+
estrutura = ESTRUTURA[operacao]
|
16
|
+
|
17
|
+
@header = estrutura[:header].new
|
18
|
+
@trailer = estrutura[:trailer].new
|
19
|
+
|
20
|
+
estrutura[:segmentos].each do |s|
|
21
|
+
self << s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def <<(s)
|
26
|
+
segmentos[s] = eval("Segmento#{s.to_s.upcase}.new")
|
27
|
+
add_segmento_accessors(s)
|
28
|
+
end
|
29
|
+
|
30
|
+
def linhas
|
31
|
+
seg_array = Array.new
|
32
|
+
estrutura = ESTRUTURA[operacao]
|
33
|
+
estrutura[:segmentos].each do |s|
|
34
|
+
seg_array << @segmentos[s].linha
|
35
|
+
end
|
36
|
+
seg_array
|
37
|
+
end
|
38
|
+
|
39
|
+
def string
|
40
|
+
linhas.join("\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def add_segmento_accessors(segmento)
|
46
|
+
instance_eval <<-RUBY, __FILE__, __LINE__ + 1
|
47
|
+
def segmento_#{segmento.to_s.downcase}
|
48
|
+
segmentos[:#{segmento.to_s.downcase}]
|
49
|
+
end
|
50
|
+
def segmento_#{segmento.to_s.downcase}=(s)
|
51
|
+
segmentos[:#{segmento.to_s.downcase}] = s
|
52
|
+
end
|
53
|
+
RUBY
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/cnab240/version.rb
CHANGED
data/lib/cnab240.rb
CHANGED
@@ -6,6 +6,8 @@ require "cnab240/core_ext/attribute_accessors"
|
|
6
6
|
require "cnab240/core_ext/bindata"
|
7
7
|
require "cnab240/core_ext/default_mixin"
|
8
8
|
|
9
|
+
require "cnab240/arquivo/lote"
|
10
|
+
|
9
11
|
require "cnab240/segmentos/segmento_a"
|
10
12
|
require "cnab240/segmentos/segmento_b"
|
11
13
|
require "cnab240/segmentos/segmento_c"
|
@@ -16,11 +18,18 @@ require "cnab240/arquivo/trailer"
|
|
16
18
|
|
17
19
|
require "cnab240/pagamentos/header"
|
18
20
|
require "cnab240/pagamentos/trailer"
|
19
|
-
require "cnab240/pagamentos/lote"
|
20
21
|
|
21
22
|
|
22
23
|
module Cnab240
|
23
24
|
|
25
|
+
ESTRUTURA = {
|
26
|
+
:pagamento => {
|
27
|
+
:header => Cnab240::Pagamentos::Header,
|
28
|
+
:trailer => Cnab240::Pagamentos::Trailer,
|
29
|
+
:segmentos => [:a, :b, :c]
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
24
33
|
mod_attr_accessor :defaults
|
25
34
|
@@defaults = {}
|
26
35
|
|
@@ -15,8 +15,8 @@ describe Arquivo do
|
|
15
15
|
arquivo.should respond_to(:lotes)
|
16
16
|
|
17
17
|
(1..10).each do |n|
|
18
|
-
lote = Cnab240::
|
19
|
-
lote.should be_an_instance_of(Cnab240::
|
18
|
+
lote = Cnab240::Lote.new(:pagamento)
|
19
|
+
lote.should be_an_instance_of(Cnab240::Lote)
|
20
20
|
arquivo.lotes << lote
|
21
21
|
arquivo.lotes.length.should be(n)
|
22
22
|
end
|
@@ -27,8 +27,8 @@ describe Arquivo do
|
|
27
27
|
arquivo.should respond_to(:lotes)
|
28
28
|
|
29
29
|
(1..10).each do |n|
|
30
|
-
lote = Cnab240::
|
31
|
-
lote.should be_an_instance_of(Cnab240::
|
30
|
+
lote = Cnab240::Lote.new(:pagamento)
|
31
|
+
lote.should be_an_instance_of(Cnab240::Lote)
|
32
32
|
arquivo.lotes << lote
|
33
33
|
end
|
34
34
|
|
@@ -3,9 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Cnab240::Pagamentos::Header do
|
4
4
|
|
5
5
|
it "deve conter campos header" do
|
6
|
-
|
7
|
-
|
8
|
-
header = lote.header
|
6
|
+
header = Cnab240::Pagamentos::Header.new
|
9
7
|
|
10
8
|
header.should respond_to(:controle_banco)
|
11
9
|
header.should respond_to(:controle_lote)
|
@@ -48,8 +46,8 @@ describe Cnab240::Pagamentos::Header do
|
|
48
46
|
|
49
47
|
|
50
48
|
it "header deve ter 240 caracteres" do
|
51
|
-
|
52
|
-
|
49
|
+
header = Cnab240::Pagamentos::Header.new
|
50
|
+
header.linha.length.should be(240)
|
53
51
|
end
|
54
52
|
|
55
53
|
end
|
@@ -1,26 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Cnab240::
|
3
|
+
describe Cnab240::Lote do
|
4
4
|
|
5
5
|
it "deve conter trailer e header" do
|
6
|
-
lote = Cnab240::
|
6
|
+
lote = Cnab240::Lote.new(:pagamento)
|
7
7
|
lote.header.should be_an_instance_of(Cnab240::Pagamentos::Header)
|
8
8
|
lote.trailer.should be_an_instance_of(Cnab240::Pagamentos::Trailer)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "deve conter segmento a" do
|
12
|
-
lote = Cnab240::
|
12
|
+
lote = Cnab240::Lote.new(:pagamento)
|
13
13
|
lote.segmento_a.should be_an_instance_of(Cnab240::SegmentoA)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "deve conter segmento b" do
|
17
|
-
lote = Cnab240::
|
17
|
+
lote = Cnab240::Lote.new(:pagamento)
|
18
18
|
lote.segmento_b.should be_an_instance_of(Cnab240::SegmentoB)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "pode conter segmento c" do
|
22
|
-
lote = Cnab240::
|
22
|
+
lote = Cnab240::Lote.new(:pagamento)
|
23
23
|
lote.should respond_to(:segmento_c)
|
24
24
|
end
|
25
25
|
|
26
|
+
it "linhas devem ter 240" do
|
27
|
+
lote = Cnab240::Lote.new(:pagamento)
|
28
|
+
lote.linhas.each do |linha|
|
29
|
+
linha.length.should be(240)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
26
34
|
end
|
@@ -3,9 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Cnab240::Pagamentos::Trailer do
|
4
4
|
|
5
5
|
it "deve conter campos trailer" do
|
6
|
-
|
7
|
-
|
8
|
-
trailer = lote.trailer
|
6
|
+
trailer = Cnab240::Pagamentos::Trailer.new
|
9
7
|
|
10
8
|
trailer.should respond_to(:controle_banco)
|
11
9
|
trailer.should respond_to(:controle_lote)
|
@@ -25,8 +23,8 @@ describe Cnab240::Pagamentos::Trailer do
|
|
25
23
|
end
|
26
24
|
|
27
25
|
it "trailer deve ter 240 caracteres" do
|
28
|
-
|
29
|
-
|
26
|
+
trailer = Cnab240::Pagamentos::Trailer.new
|
27
|
+
trailer.linha.length.should be(240)
|
30
28
|
end
|
31
29
|
|
32
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cnab240
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -61,12 +61,12 @@ files:
|
|
61
61
|
- lib/cnab240.rb
|
62
62
|
- lib/cnab240/arquivo/arquivo.rb
|
63
63
|
- lib/cnab240/arquivo/header.rb
|
64
|
+
- lib/cnab240/arquivo/lote.rb
|
64
65
|
- lib/cnab240/arquivo/trailer.rb
|
65
66
|
- lib/cnab240/core_ext/attribute_accessors.rb
|
66
67
|
- lib/cnab240/core_ext/bindata.rb
|
67
68
|
- lib/cnab240/core_ext/default_mixin.rb
|
68
69
|
- lib/cnab240/pagamentos/header.rb
|
69
|
-
- lib/cnab240/pagamentos/lote.rb
|
70
70
|
- lib/cnab240/pagamentos/trailer.rb
|
71
71
|
- lib/cnab240/segmentos/segmento_a.rb
|
72
72
|
- lib/cnab240/segmentos/segmento_b.rb
|
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
segments:
|
99
99
|
- 0
|
100
|
-
hash: -
|
100
|
+
hash: -2630031989102335816
|
101
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
102
|
none: false
|
103
103
|
requirements:
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
segments:
|
108
108
|
- 0
|
109
|
-
hash: -
|
109
|
+
hash: -2630031989102335816
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project: cnab240
|
112
112
|
rubygems_version: 1.8.24
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Cnab240::Pagamentos
|
2
|
-
class Lote
|
3
|
-
attr_accessor :header
|
4
|
-
attr_accessor :segmento_a
|
5
|
-
attr_accessor :segmento_b
|
6
|
-
attr_accessor :segmento_c
|
7
|
-
attr_accessor :trailer
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@header = Header.new
|
11
|
-
@segmento_a = SegmentoA.new
|
12
|
-
@segmento_b = SegmentoB.new
|
13
|
-
@trailer = Trailer.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def linhas
|
17
|
-
@segmento_c.nil? ? [@header, @segmento_a, @segmento_b, @trailer] : [@header, @segmento_a, @segmento_b, @segmento_c, @trailer]
|
18
|
-
end
|
19
|
-
|
20
|
-
def string
|
21
|
-
linhas.join("\n")
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|