cnab_rb 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.
@@ -0,0 +1,86 @@
1
+ module CnabRb::Layouts::Cnab240::Generic
2
+ class TrailerBatch < CnabRb::Layouts::Layout
3
+ def init_fields
4
+ field :banck_code,
5
+ # codigo_banco
6
+ pos: 1..3,
7
+ picture: '9(3)'
8
+
9
+ field :service_batch,
10
+ # lote_servico
11
+ pos: 4..7,
12
+ picture: '9(4)'
13
+
14
+ field :registry_type,
15
+ # tipo_registro
16
+ pos: 8..8,
17
+ picture: '9(1)',
18
+ default: '5'
19
+
20
+ field :exclusive_use_febraban_1,
21
+ # uso_exclusivo_febraban_01
22
+ pos: 9..17,
23
+ picture: 'X(9)',
24
+ default: ''
25
+
26
+ field :batch_registry_quantity,
27
+ # qtde_registro_lote
28
+ pos: 18..23,
29
+ picture: '9(6)'
30
+
31
+ field :simple_charge_quantity,
32
+ # qtde_titulo_cobranca_simples
33
+ pos: 24..29,
34
+ picture: '9(6)'
35
+
36
+ field :simple_charge_total_amount,
37
+ # valor_total_titulo_simples
38
+ pos: 30..46,
39
+ picture: '9(15)V9(2)'
40
+
41
+ field :exclusive_use_febraban_2,
42
+ # uso_exclusivo_febraban_02
43
+ pos: 47..52,
44
+ picture: 'X(6)',
45
+ default: ''
46
+
47
+ field :exclusive_use_febraban_3,
48
+ # uso_exclusivo_febraban_03
49
+ pos: 53..69,
50
+ picture: '9(15)V9(2)',
51
+ default: '0'
52
+
53
+ field :secured_charge_quantity,
54
+ # qtde_titulo_cobranca_caucionada
55
+ pos: 70..75,
56
+ picture: '9(6)'
57
+
58
+ field :secured_charge_total_amount,
59
+ # valor_total_titulo_caucionada
60
+ pos: 76..92,
61
+ picture: '9(15)V9(2)'
62
+
63
+ field :discount_charge_quantity,
64
+ # qtde_titulo_cobranca_descontada
65
+ pos: 93..98,
66
+ picture: '9(6)'
67
+
68
+ field :discount_charge_total_amount,
69
+ # valor_total_titulo_descontada
70
+ pos: 99..115,
71
+ picture: '9(15)V9(2)'
72
+
73
+ field :exclusive_use_febraban_4,
74
+ # uso_exclusivo_febraban_04
75
+ pos: 116..123,
76
+ picture: 'X(8)',
77
+ default: ''
78
+
79
+ field :exclusive_use_febraban_5,
80
+ # uso_exclusivo_febraban_05
81
+ pos: 124..240,
82
+ picture: 'X(117)',
83
+ default: ''
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,50 @@
1
+ module CnabRb::Layouts::Cnab240::Generic
2
+ class TrailerFile < CnabRb::Layouts::Layout
3
+ def init_fields
4
+ field :bank_code,
5
+ # codigo_banco
6
+ pos: 1..3,
7
+ picture: '9(3)'
8
+
9
+ field :service_batch,
10
+ # lote_servico
11
+ pos: 4..7,
12
+ picture: '9(4)',
13
+ default: '9999'
14
+
15
+ field :registry_type,
16
+ # tipo_registro
17
+ pos: 8..8,
18
+ picture: '9(1)',
19
+ default: '9'
20
+
21
+ field :exclusive_use_febraban_1,
22
+ # uso_exclusivo_febraban01
23
+ pos: 9..17,
24
+ picture: 'X(9)',
25
+ default: ''
26
+
27
+ field :batch_quantity,
28
+ # qtde_lotes
29
+ pos: 18..23,
30
+ picture: '9(6)'
31
+
32
+ field :registry_quantity,
33
+ # qtde_registros
34
+ pos: 24..29,
35
+ picture: '9(6)'
36
+
37
+ field :exclusive_use_febraban_2,
38
+ # uso_exclusivo_febraban02
39
+ pos: 30..35,
40
+ picture: 'X(6)',
41
+ default: ''
42
+
43
+ field :exclusive_use_febraban_3,
44
+ # uso_exclusivo_febraban_03
45
+ pos: 36..240,
46
+ picture: 'X(205)',
47
+ default: ''
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,40 @@
1
+ module CnabRb::Layouts
2
+ class Layout
3
+ attr_accessor :fields
4
+
5
+ def initialize
6
+ @fields = {}
7
+ init_fields
8
+ end
9
+
10
+ def init_fields
11
+ end
12
+
13
+ def field(name, params)
14
+ clean(params[:pos])
15
+ @fields[name] = CnabRb::Format::Field.new(params)
16
+ end
17
+
18
+ def clean(range)
19
+ @fields.reject! do |key, field|
20
+ range.cover?(field.range.begin) || field.range.cover?(range.begin)
21
+ end
22
+ end
23
+
24
+ def validate!
25
+ expected_line_length = ordered_fields.last[1].pos_end
26
+ actual_line_length = @fields.sum do |key, field|
27
+ field.validate!
28
+ field.length
29
+ end
30
+
31
+ if expected_line_length != actual_line_length
32
+ raise CnabRb::Error.new("Invalid layout length, expected #{expected_line_length}, actual #{actual_line_length}")
33
+ end
34
+ end
35
+
36
+ def ordered_fields
37
+ @fields.sort_by {|key, field| field.pos_start}
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module CnabRb::Return::Cnab240
2
+ class CaixaReturn < Cnab::Return::Cnab240::GenericReturn
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module CnabRb::Return::Cnab240
2
+ class GenericReturn < Cnab::Format::File
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ module CnabRb::Return
2
+ class ReturnFactory
3
+ def make_return(file_name)
4
+ first_line = File.open(file_name, &:readline)
5
+ format = first_line.gsub(/(\r|\n)$/, '').length
6
+ bank_code = first_line[0, 3]
7
+ method = "make_cnab#{format}_#{bank_code}"
8
+
9
+ unless respond_to?(method)
10
+ raise NotImplementedError.new("Format not implemented")
11
+ end
12
+
13
+ send(method, file_name)
14
+ end
15
+
16
+ def make_cnab240_104(file_name)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module CnabRb
2
+ VERSION = "0.1.0"
3
+ end
data/lib/cnab_rb.rb ADDED
@@ -0,0 +1,41 @@
1
+ require "cnab_rb/version"
2
+
3
+ module CnabRb
4
+ class Error < StandardError; end
5
+
6
+ module Format
7
+ module PictureFormats
8
+ autoload :Float, 'cnab_rb/format/picture_formats/float'
9
+ autoload :Integer, 'cnab_rb/format/picture_formats/integer'
10
+ autoload :Text, 'cnab_rb/format/picture_formats/text'
11
+ end
12
+
13
+ autoload :Field, 'cnab_rb/format/field'
14
+ autoload :File, 'cnab_rb/format/file'
15
+ autoload :Line, 'cnab_rb/format/line'
16
+ autoload :Picture, 'cnab_rb/format/picture'
17
+ end
18
+
19
+ module Layouts
20
+ module Cnab240
21
+ module Generic
22
+ module Return
23
+ autoload :SegmentA, 'cnab_rb/layouts/cnab240/generic/segment_a'
24
+ autoload :SegmentT, 'cnab_rb/layouts/cnab240/generic/segment_t'
25
+ autoload :SegmentU, 'cnab_rb/layouts/cnab240/generic/segment_u'
26
+ autoload :SegmentW, 'cnab_rb/layouts/cnab240/generic/segment_w'
27
+ end
28
+
29
+ autoload :HeaderFile, 'cnab_rb/layouts/cnab240/generic/header_file'
30
+ autoload :HeaderBatch, 'cnab_rb/layouts/cnab240/generic/header_batch'
31
+ autoload :TrailerBatch, 'cnab_rb/layouts/cnab240/generic/trailer_batch'
32
+ autoload :TrailerFile, 'cnab_rb/layouts/cnab240/generic/trailer_file'
33
+ end
34
+ end
35
+ autoload :Layout, 'cnab_rb/layouts/layout'
36
+ end
37
+
38
+ module Return
39
+ autoload :ReturnFactory, 'cnab_rb/return/return_factory'
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cnab_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anderson Danilo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - contato@andersondanilo.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".editorconfig"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - cnab_rb.gemspec
74
+ - lib/cnab_rb.rb
75
+ - lib/cnab_rb/format/field.rb
76
+ - lib/cnab_rb/format/file.rb
77
+ - lib/cnab_rb/format/line.rb
78
+ - lib/cnab_rb/format/picture.rb
79
+ - lib/cnab_rb/format/picture_formats/float.rb
80
+ - lib/cnab_rb/format/picture_formats/integer.rb
81
+ - lib/cnab_rb/format/picture_formats/text.rb
82
+ - lib/cnab_rb/layouts/cnab240/generic/header_batch.rb
83
+ - lib/cnab_rb/layouts/cnab240/generic/header_file.rb
84
+ - lib/cnab_rb/layouts/cnab240/generic/return/segment_a.rb
85
+ - lib/cnab_rb/layouts/cnab240/generic/return/segment_t.rb
86
+ - lib/cnab_rb/layouts/cnab240/generic/return/segment_u.rb
87
+ - lib/cnab_rb/layouts/cnab240/generic/return/segment_w.rb
88
+ - lib/cnab_rb/layouts/cnab240/generic/trailer_batch.rb
89
+ - lib/cnab_rb/layouts/cnab240/generic/trailer_file.rb
90
+ - lib/cnab_rb/layouts/layout.rb
91
+ - lib/cnab_rb/return/cnab240/caixa_return.rb
92
+ - lib/cnab_rb/return/cnab240/generic_return.rb
93
+ - lib/cnab_rb/return/return_factory.rb
94
+ - lib/cnab_rb/version.rb
95
+ homepage: https://github.com/andersondanilo/cnab_rb
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ homepage_uri: https://github.com/andersondanilo/cnab_rb
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.0.4
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: CNAB 240 e 400 to brazillian banks.
119
+ test_files: []