rocknab 0.1.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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +42 -0
- data/LICENSE +21 -0
- data/Rakefile +6 -0
- data/lib/rocknab/builder.rb +139 -0
- data/lib/rocknab/builder/date.rb +11 -0
- data/lib/rocknab/builder/number.rb +10 -0
- data/lib/rocknab/builder/padding.rb +9 -0
- data/lib/rocknab/builder/text.rb +10 -0
- data/lib/rocknab/layouts/cnab_240.rb +80 -0
- data/lib/rocknab/layouts/cnab_240/batch.rb +89 -0
- data/lib/rocknab/layouts/cnab_240/batch_header.rb +49 -0
- data/lib/rocknab/layouts/cnab_240/batch_trailer.rb +21 -0
- data/lib/rocknab/layouts/cnab_240/header.rb +43 -0
- data/lib/rocknab/layouts/cnab_240/segment.rb +56 -0
- data/lib/rocknab/layouts/cnab_240/trailer.rb +18 -0
- data/lib/rocknab/version.rb +3 -0
- data/rocknab.gemspec +23 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1bc7d036063fff49854aa56b7c77da724780c65201ffef3e872e40e945011720
|
4
|
+
data.tar.gz: 9298a235e01f6ce1254a7458b638534612f7fc6fd7a84f889bdb1cb77cb74e71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4063101f14520e296a21c09ee7a2e6b9aaa611a760057c8b270fa7e2818d5ebdbaf4b0ac6f6402476dc611a52738d8d3e801e5df6dca902f221536e83a29666a
|
7
|
+
data.tar.gz: e3ab888d884d2c03526a5706d23046d90f6226889ad51e78d1b38efce339de769a052770bf8e21c289f230175f05937da191252343c428d81648c331a9f4d954
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rocknab (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
method_source (0.9.0)
|
12
|
+
pry (0.11.3)
|
13
|
+
coderay (~> 1.1.0)
|
14
|
+
method_source (~> 0.9.0)
|
15
|
+
pry-rails (0.3.6)
|
16
|
+
pry (>= 0.10.4)
|
17
|
+
rake (10.5.0)
|
18
|
+
rspec (3.8.0)
|
19
|
+
rspec-core (~> 3.8.0)
|
20
|
+
rspec-expectations (~> 3.8.0)
|
21
|
+
rspec-mocks (~> 3.8.0)
|
22
|
+
rspec-core (3.8.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-expectations (3.8.2)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-mocks (3.8.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.8.0)
|
30
|
+
rspec-support (3.8.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
pry-rails (~> 0.3)
|
37
|
+
rake (~> 10.0)
|
38
|
+
rocknab!
|
39
|
+
rspec (~> 3.0)
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
1.16.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Rock Content
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require_relative "builder/text"
|
2
|
+
require_relative "builder/number"
|
3
|
+
require_relative "builder/date"
|
4
|
+
require_relative "builder/padding"
|
5
|
+
|
6
|
+
module Rocknab
|
7
|
+
# This is the DSL that is used to declare CNAB registers
|
8
|
+
#
|
9
|
+
# Declaration:
|
10
|
+
#
|
11
|
+
# class MyRegister < Rocknab::Builder
|
12
|
+
# text :txt_field, length: 4
|
13
|
+
# number :num_field, length: 2
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# To use the class:
|
17
|
+
#
|
18
|
+
# register = MyRegister.new(txt_field: "text", num_field: 10)
|
19
|
+
# register.build
|
20
|
+
# => "TEXT10"
|
21
|
+
class Builder
|
22
|
+
# Subclasses can be initialized with the arguments passed as a
|
23
|
+
# hash, just like a Struct.
|
24
|
+
#
|
25
|
+
# Usage:
|
26
|
+
#
|
27
|
+
# MyRegister.new(txt_field: "text", num_field: 10)
|
28
|
+
def initialize(**args)
|
29
|
+
args.each do |key, value|
|
30
|
+
instance_variable_set("@#{key}", value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Builds the class according to the definition
|
35
|
+
#
|
36
|
+
# Usage:
|
37
|
+
#
|
38
|
+
# register.build
|
39
|
+
# => "TEXT10"
|
40
|
+
def build
|
41
|
+
self.class.metadata.map do |field|
|
42
|
+
field.build(self)
|
43
|
+
end.join
|
44
|
+
end
|
45
|
+
|
46
|
+
# Declares that the generated content has a text field
|
47
|
+
#
|
48
|
+
# Parameters:
|
49
|
+
# - name: Name of the field accessors
|
50
|
+
# - length: Fixed length of the field
|
51
|
+
# - default: Default value. Empty if not specified.
|
52
|
+
# - padding: Padding character. Whitespace, if not specified.
|
53
|
+
#
|
54
|
+
# Usage:
|
55
|
+
#
|
56
|
+
# class MyRegister < Rocknab::Builder
|
57
|
+
# text :my_field, length: 20, default: "hello", padding: " "
|
58
|
+
# end
|
59
|
+
def self.text(name, length: 1, default: " ", padding: " ")
|
60
|
+
metadata << Builders::Text.new(name, length, default, padding)
|
61
|
+
attr_accessor(name)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Declares that the generated content has a numeric field.
|
65
|
+
# This field should only be used for integers.
|
66
|
+
#
|
67
|
+
# Parameters:
|
68
|
+
# - name: Name of the field accessors
|
69
|
+
# - length: Fixed length of the field
|
70
|
+
# - default: Default value. Zero if not specified.
|
71
|
+
# - padding: Padding character. Zeros, if not specified.
|
72
|
+
#
|
73
|
+
# Usage:
|
74
|
+
#
|
75
|
+
# class MyRegister < Rocknab::Builder
|
76
|
+
# number :my_num, length: 20, default: 1234, padding: 0
|
77
|
+
# end
|
78
|
+
def self.number(name, length: 1, default: 0, padding: 0)
|
79
|
+
metadata << Builders::Number.new(name, length, default, padding)
|
80
|
+
attr_accessor(name)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Declares that the generated content has a date field. The
|
84
|
+
# format is DDMMYYYYhhmmss.
|
85
|
+
#
|
86
|
+
# Parameters:
|
87
|
+
# - name: Name of the field accessors
|
88
|
+
# - length: Fixed length of the field. Default is 14.
|
89
|
+
# - default: Default value. Zeroes if not specified.
|
90
|
+
# - padding: Padding character. Zeros, if not specified.
|
91
|
+
#
|
92
|
+
# Tip: Use 10 as the length, if you only need the date.
|
93
|
+
#
|
94
|
+
# Usage:
|
95
|
+
#
|
96
|
+
# class MyRegister < Rocknab::Builder
|
97
|
+
# date :created_at, length: 14, default: "hello", padding: " "
|
98
|
+
# end
|
99
|
+
def self.date(name, length: 14, default: 0, padding: 0)
|
100
|
+
metadata << Builders::Date.new(name, length, default, padding)
|
101
|
+
attr_accessor(name)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Declares that the generated content has a padding
|
105
|
+
#
|
106
|
+
# Parameters:
|
107
|
+
# - length: Fixed length of the field
|
108
|
+
# - char: Character that will be used to pad the content.
|
109
|
+
# The default is whitespace.
|
110
|
+
#
|
111
|
+
# Usage:
|
112
|
+
#
|
113
|
+
# padding length: 10, char: "0"
|
114
|
+
def self.padding(length: 1, char: " ")
|
115
|
+
metadata << Builders::Padding.new(length, char)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns the total length of the fields. Useful for validation
|
119
|
+
# purposes and testing.
|
120
|
+
#
|
121
|
+
# Usage:
|
122
|
+
#
|
123
|
+
# MyRegister.length
|
124
|
+
# => 240
|
125
|
+
def self.length
|
126
|
+
metadata.map(&:length).reduce(&:+)
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.inherited(child)
|
130
|
+
child.instance_eval do
|
131
|
+
class << self
|
132
|
+
attr_accessor :metadata
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
child.metadata = []
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Rocknab
|
2
|
+
module Builders
|
3
|
+
class Date < Struct.new(:name, :length, :default, :padding)
|
4
|
+
def build(klass)
|
5
|
+
value = klass.instance_variable_get("@#{name}") || default
|
6
|
+
str_value = value.strftime("%d%m%Y%H%M%S")
|
7
|
+
str_value[0...length].ljust(length, padding.to_s)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative "../builder"
|
2
|
+
require_relative "cnab_240/header"
|
3
|
+
require_relative "cnab_240/batch"
|
4
|
+
require_relative "cnab_240/trailer"
|
5
|
+
|
6
|
+
module Rocknab
|
7
|
+
module Layouts
|
8
|
+
module CNAB240
|
9
|
+
# This is the class that builds a CNAB240 file.
|
10
|
+
#
|
11
|
+
# Parameters:
|
12
|
+
# - params: A hash containing the following values:
|
13
|
+
# :cnpj, :branch, :account, :digit, :name, :bank, :date,
|
14
|
+
# :zipcode, :state
|
15
|
+
# - payments: An array of hashes, each with the following:
|
16
|
+
# :bank, :branch, :account, :digit, :name, :date, :value
|
17
|
+
#
|
18
|
+
# Usage:
|
19
|
+
#
|
20
|
+
# cnab = CNAB240.new(params, payments)
|
21
|
+
# cnab.build
|
22
|
+
# => "... CNAB content ..."
|
23
|
+
class CNAB240 < Struct.new(:params, :payments)
|
24
|
+
HEADER_PARAMS = [ :bank_code, :cnpj, :branch, :account, :digit, :name,
|
25
|
+
:bank, :date ]
|
26
|
+
TRAILER_PARAMS = [ :bank_code ]
|
27
|
+
|
28
|
+
# Builds the CNAB 240 v81 file according to the contents
|
29
|
+
#
|
30
|
+
# Usage:
|
31
|
+
#
|
32
|
+
# cnab.build
|
33
|
+
# => "... CNAB content ..."
|
34
|
+
def build
|
35
|
+
[ header, batches, trailer, nil ].join("\r\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def header
|
41
|
+
Header.new(params.slice(*HEADER_PARAMS)).build
|
42
|
+
end
|
43
|
+
|
44
|
+
def batches
|
45
|
+
batch_groups.each_with_index.map do |group, index|
|
46
|
+
config, batch_payments = group
|
47
|
+
is_same_bank = config[:is_same_bank]
|
48
|
+
is_ted = config[:is_ted]
|
49
|
+
is_savings = config[:is_savings]
|
50
|
+
Batch.new(params, batch_payments, is_same_bank, is_ted, is_savings, index + 1).build
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def batch_groups
|
55
|
+
payments.group_by do |payment|
|
56
|
+
is_same_bank = payment.dig(:bank) === params.dig(:bank_code)
|
57
|
+
is_ted = payment.dig(:is_ted)
|
58
|
+
is_savings = payment.dig(:is_savings)
|
59
|
+
|
60
|
+
{
|
61
|
+
is_same_bank: is_same_bank,
|
62
|
+
is_ted: !is_same_bank && is_ted,
|
63
|
+
is_savings: is_savings,
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def trailer
|
69
|
+
default_params = {
|
70
|
+
register_count: batches.flatten.count + 2,
|
71
|
+
batch_count: batches.length
|
72
|
+
}
|
73
|
+
line_params = params.slice(*TRAILER_PARAMS).merge(default_params)
|
74
|
+
|
75
|
+
Trailer.new(line_params).build
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require_relative "batch_header"
|
2
|
+
require_relative "batch_trailer"
|
3
|
+
require_relative "segment"
|
4
|
+
|
5
|
+
module Rocknab
|
6
|
+
module Layouts
|
7
|
+
module CNAB240
|
8
|
+
class Batch < Struct.new(:params, :payments, :is_same_bank, :is_ted, :is_savings,
|
9
|
+
:batch_index)
|
10
|
+
BATCH_PARAMS = [ :bank_code, :cnpj, :branch, :account, :digit, :name,
|
11
|
+
:zipcode, :state, :payment_type, :payment_reason ]
|
12
|
+
SEGMENT_PARAMS = [ :bank_code, :bank, :branch, :account, :digit, :name,
|
13
|
+
:date, :value, :inscription_number ]
|
14
|
+
TRAILER_PARAMS = [ :bank_code ]
|
15
|
+
|
16
|
+
def build
|
17
|
+
[ batch_header, segments, batch_trailer ]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def batch_header
|
23
|
+
default_params = {
|
24
|
+
batch_index: batch_index,
|
25
|
+
payment_method: payment_method,
|
26
|
+
}
|
27
|
+
line_params = params.slice(*BATCH_PARAMS).merge(default_params)
|
28
|
+
|
29
|
+
BatchHeader.new(line_params).build
|
30
|
+
end
|
31
|
+
|
32
|
+
def segments
|
33
|
+
payments.each_with_index.map do |payment, index|
|
34
|
+
default_params = {
|
35
|
+
batch_index: batch_index,
|
36
|
+
segment_index: index + 1,
|
37
|
+
bank_code: params.dig(:bank_code),
|
38
|
+
doc_type: doc_type,
|
39
|
+
}
|
40
|
+
line_params = payment.slice(*SEGMENT_PARAMS).merge(default_params)
|
41
|
+
|
42
|
+
Segment.new(line_params).build
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def batch_trailer
|
47
|
+
default_params = {
|
48
|
+
batch_index: batch_index,
|
49
|
+
register_count: register_count,
|
50
|
+
total_sum: total_sum,
|
51
|
+
}
|
52
|
+
line_params = params.slice(*TRAILER_PARAMS).merge(default_params)
|
53
|
+
|
54
|
+
BatchTrailer.new(line_params).build
|
55
|
+
end
|
56
|
+
|
57
|
+
def payment_method
|
58
|
+
if is_same_bank && is_savings
|
59
|
+
5
|
60
|
+
elsif is_same_bank
|
61
|
+
1
|
62
|
+
elsif is_ted
|
63
|
+
41
|
64
|
+
else
|
65
|
+
3
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def doc_type
|
70
|
+
if is_savings && !is_same_bank
|
71
|
+
"11"
|
72
|
+
else
|
73
|
+
""
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def register_count
|
78
|
+
payments.count + 2
|
79
|
+
end
|
80
|
+
|
81
|
+
def total_sum
|
82
|
+
payments.inject(0) do |sum, payment|
|
83
|
+
sum + payment.dig(:value)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Rocknab
|
2
|
+
module Layouts
|
3
|
+
module CNAB240
|
4
|
+
class BatchHeader < Rocknab::Builder
|
5
|
+
number :bank_code, length: 3, default: 0
|
6
|
+
number :batch_index, length: 4, default: 1
|
7
|
+
number :register_type, length: 1, default: 1
|
8
|
+
|
9
|
+
text :operation_type, length: 1, default: "C"
|
10
|
+
number :payment_type, length: 2, default: 98
|
11
|
+
number :payment_method, length: 2, default: 1
|
12
|
+
number :batch_layout, length: 3, default: 40
|
13
|
+
|
14
|
+
padding length: 1
|
15
|
+
|
16
|
+
number :company_type, length: 1, default: 2
|
17
|
+
number :cnpj, length: 14
|
18
|
+
text :indentification, length: 4
|
19
|
+
|
20
|
+
padding length: 16
|
21
|
+
|
22
|
+
number :branch, length: 5
|
23
|
+
|
24
|
+
padding length: 1
|
25
|
+
|
26
|
+
number :account, length: 12
|
27
|
+
|
28
|
+
padding length: 1
|
29
|
+
|
30
|
+
text :digit, length: 1
|
31
|
+
text :name, length: 30
|
32
|
+
|
33
|
+
text :payment_reason, length: 30, default: "01"
|
34
|
+
text :account_history, length: 10
|
35
|
+
|
36
|
+
text :street, length: 30
|
37
|
+
number :number, length: 5
|
38
|
+
text :type, length: 15
|
39
|
+
text :city, length: 20
|
40
|
+
text :zipcode, length: 8
|
41
|
+
text :state, length: 2
|
42
|
+
|
43
|
+
padding length: 8
|
44
|
+
|
45
|
+
text :return_code, length: 10
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rocknab
|
2
|
+
module Layouts
|
3
|
+
module CNAB240
|
4
|
+
class BatchTrailer < Rocknab::Builder
|
5
|
+
number :bank_code, length: 3, default: 0
|
6
|
+
number :batch_index, length: 4, default: 1
|
7
|
+
number :register_type, length: 1, default: 5
|
8
|
+
|
9
|
+
padding length: 9
|
10
|
+
|
11
|
+
number :register_count, length: 6
|
12
|
+
number :total_sum, length: 18
|
13
|
+
|
14
|
+
padding length: 18, char: "0"
|
15
|
+
padding length: 171
|
16
|
+
|
17
|
+
text :return_code, length: 10
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rocknab
|
2
|
+
module Layouts
|
3
|
+
module CNAB240
|
4
|
+
class Header < Rocknab::Builder
|
5
|
+
number :bank_code, length: 3, default: 0
|
6
|
+
number :batch_index, length: 4, default: 0
|
7
|
+
number :register_type, length: 1, default: 0
|
8
|
+
|
9
|
+
padding length: 6
|
10
|
+
|
11
|
+
number :file_version, length: 3, default: 80
|
12
|
+
|
13
|
+
number :company_type, length: 1, default: 2
|
14
|
+
number :cnpj, length: 14
|
15
|
+
|
16
|
+
padding length: 20
|
17
|
+
|
18
|
+
number :branch, length: 5
|
19
|
+
|
20
|
+
padding length: 1
|
21
|
+
|
22
|
+
number :account, length: 12
|
23
|
+
|
24
|
+
padding length: 1
|
25
|
+
|
26
|
+
number :digit, length: 1
|
27
|
+
text :name, length: 30
|
28
|
+
text :bank, length: 30
|
29
|
+
|
30
|
+
padding length: 10
|
31
|
+
|
32
|
+
number :file_type, length: 1, default: 1
|
33
|
+
date :date, length: 14
|
34
|
+
|
35
|
+
padding length: 9, char: "0"
|
36
|
+
|
37
|
+
number :density_unit, length: 5
|
38
|
+
|
39
|
+
padding length: 69
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Rocknab
|
2
|
+
module Layouts
|
3
|
+
module CNAB240
|
4
|
+
class Segment < Rocknab::Builder
|
5
|
+
number :bank_code, length: 3, default: 0
|
6
|
+
number :batch_index, length: 4, default: 1
|
7
|
+
number :register_type, length: 1, default: 3
|
8
|
+
number :segment_index, length: 5, default: 1
|
9
|
+
|
10
|
+
text :segment_type, length: 1, default: "A"
|
11
|
+
number :service_type, length: 3, default: 0
|
12
|
+
|
13
|
+
padding length: 3, char: "0"
|
14
|
+
|
15
|
+
number :bank, length: 3, default: 0
|
16
|
+
number :branch, length: 5
|
17
|
+
|
18
|
+
padding length: 1
|
19
|
+
|
20
|
+
number :account, length: 12
|
21
|
+
|
22
|
+
padding length: 1
|
23
|
+
|
24
|
+
number :digit, length: 1
|
25
|
+
text :name, length: 30
|
26
|
+
|
27
|
+
text :document_number, length: 20
|
28
|
+
date :date, length: 8
|
29
|
+
text :currency_type, length: 3, default: "REA"
|
30
|
+
|
31
|
+
padding length: 15, char: "0"
|
32
|
+
|
33
|
+
number :value, length: 15
|
34
|
+
text :our_number, length: 15
|
35
|
+
|
36
|
+
padding length: 5
|
37
|
+
|
38
|
+
number :actual_date, length: 8
|
39
|
+
number :actual_value, length: 15
|
40
|
+
|
41
|
+
text :cnpj_number, length: 14
|
42
|
+
|
43
|
+
padding length: 6
|
44
|
+
|
45
|
+
number :operation_number, length: 6
|
46
|
+
number :inscription_number, length: 14
|
47
|
+
text :doc_type, length: 2
|
48
|
+
text :ted_type, length: 5
|
49
|
+
|
50
|
+
text :complement, length: 5
|
51
|
+
text :notice, length: 1, default: "0"
|
52
|
+
text :occurrencies, length: 10
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Rocknab
|
2
|
+
module Layouts
|
3
|
+
module CNAB240
|
4
|
+
class Trailer < Rocknab::Builder
|
5
|
+
number :bank_code, length: 3, default: 0
|
6
|
+
number :batch_index, length: 4, default: 9999
|
7
|
+
number :register_type, length: 1, default: 9
|
8
|
+
|
9
|
+
padding length: 9
|
10
|
+
|
11
|
+
number :batch_count, length: 6, default: 1
|
12
|
+
number :register_count, length: 6
|
13
|
+
|
14
|
+
padding length: 211
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/rocknab.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "rocknab/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rocknab"
|
7
|
+
spec.version = Rocknab::VERSION
|
8
|
+
spec.authors = ["Silvio Henrique Ferreira", "Rock Content"]
|
9
|
+
spec.email = ["shferreira@me.com", "services@rockcontent.com"]
|
10
|
+
spec.summary = %q{CNAB File Generator}
|
11
|
+
spec.description = %q{CNAB File Generator}
|
12
|
+
spec.homepage = "https://github.com/rockcontent/rocknab"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
22
|
+
spec.add_development_dependency "pry-rails", "~> 0.3"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rocknab
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Silvio Henrique Ferreira
|
8
|
+
- Rock Content
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '10.0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '10.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry-rails
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0.3'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.3'
|
56
|
+
description: CNAB File Generator
|
57
|
+
email:
|
58
|
+
- shferreira@me.com
|
59
|
+
- services@rockcontent.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".rspec"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE
|
68
|
+
- Rakefile
|
69
|
+
- lib/rocknab/builder.rb
|
70
|
+
- lib/rocknab/builder/date.rb
|
71
|
+
- lib/rocknab/builder/number.rb
|
72
|
+
- lib/rocknab/builder/padding.rb
|
73
|
+
- lib/rocknab/builder/text.rb
|
74
|
+
- lib/rocknab/layouts/cnab_240.rb
|
75
|
+
- lib/rocknab/layouts/cnab_240/batch.rb
|
76
|
+
- lib/rocknab/layouts/cnab_240/batch_header.rb
|
77
|
+
- lib/rocknab/layouts/cnab_240/batch_trailer.rb
|
78
|
+
- lib/rocknab/layouts/cnab_240/header.rb
|
79
|
+
- lib/rocknab/layouts/cnab_240/segment.rb
|
80
|
+
- lib/rocknab/layouts/cnab_240/trailer.rb
|
81
|
+
- lib/rocknab/version.rb
|
82
|
+
- rocknab.gemspec
|
83
|
+
homepage: https://github.com/rockcontent/rocknab
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.7.6
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: CNAB File Generator
|
107
|
+
test_files: []
|