cnab150 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +91 -15
- data/cnab150.gemspec +2 -2
- data/config/layout.yml +32 -0
- data/lib/cnab150.rb +29 -26
- data/lib/cnab150/configuration.rb +29 -0
- data/lib/cnab150/layout.rb +18 -5
- data/lib/cnab150/version.rb +1 -1
- metadata +7 -7
- data/lib/cnab150/layout/a.rb +0 -18
- data/lib/cnab150/layout/g.rb +0 -18
- data/lib/cnab150/layout/z.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0972689330a76ce6424c08cdacabf44b2b0c0e5e
|
4
|
+
data.tar.gz: bd3b712996e0dce6bffdf32d857a57dbc19eed80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32d33ed99e126b56c4d245a5e74c28f1da9e77fb2af249601ed8a4a8bf3d26b01a80c5471e278e1ffa66ca2949709b6b486a5340202828501f70203ce808f362
|
7
|
+
data.tar.gz: 975fcdadcc6d1fcbddf99715f33cd4c2250018167d3e2c4446443b8b4dc038c90115eed4e8f33fa0ea38325512ecdfebaa925e522d2d032634297fa0ecb31408
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
|
+
|
5
|
+
## [Unreleased]
|
6
|
+
|
7
|
+
## [1.3.0] - 2016-01-12
|
8
|
+
### ADDED
|
9
|
+
- Option to overried the default layouts
|
10
|
+
|
11
|
+
### CHANGED
|
12
|
+
- Layouts are now yaml file
|
data/README.md
CHANGED
@@ -27,33 +27,109 @@ Or install it yourself as:
|
|
27
27
|
$ gem install cnab150
|
28
28
|
|
29
29
|
## Usage
|
30
|
+
|
31
|
+
* The examples are using these registries
|
32
|
+
|
30
33
|
```
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
string_cnab150 = ['A20000111111111 PREF MUN XXXXXX-XYZ 341BANCO ITAU S.A. 2015101600131203 ',
|
35
|
+
'G982300210019 20151015201510168166000000005092477201510160000000000000007500000000050900000803120000701594 2 ',
|
36
|
+
'G982300210019 20151015201510168169000000023012477201510310201200230228200100000000230100000803120001183477 2 ',
|
37
|
+
'Z00000400000000001533612 ']
|
35
38
|
|
36
|
-
|
39
|
+
```
|
37
40
|
|
38
|
-
|
41
|
+
* The parser_registries method needs an array os strings, it'll return an array of Cnab150::Registry
|
42
|
+
```
|
43
|
+
> registries = Cnab150.parse_registries(string_cnab150)
|
44
|
+
=> [ Cnab150::Registry, Cnab150::Registry, Cnab150::Registry, Cnab150::Registry ]
|
45
|
+
```
|
39
46
|
|
40
|
-
|
41
|
-
|
47
|
+
* To select a kind of registry, call the select method with the type and an array os strings
|
48
|
+
```
|
49
|
+
> g_registries = Cnab150.select(:g, string_cnab150)
|
50
|
+
=> [
|
51
|
+
{ registry_code: 'G',
|
52
|
+
account: '982300210019',
|
53
|
+
payment_date: '20151015',
|
54
|
+
credit_date: '20151016',
|
55
|
+
barcode: '81660000000050924772015101600000000000000075',
|
56
|
+
value: '000000000509',
|
57
|
+
service_value: '0000080',
|
58
|
+
registry_number: '31200007',
|
59
|
+
agency: '0159',
|
60
|
+
channel: '4',
|
61
|
+
authentication: ' 2',
|
62
|
+
payment_type: '',
|
63
|
+
filler: '' },
|
64
|
+
{ registry_code: 'G',
|
65
|
+
account: '982300210019',
|
66
|
+
payment_date: '20151015',
|
67
|
+
credit_date: '20151016',
|
68
|
+
barcode: '81690000000230124772015103102012002302282001',
|
69
|
+
value: '000000002301',
|
70
|
+
service_value: '0000080',
|
71
|
+
registry_number: '31200011',
|
72
|
+
agency: '8347',
|
73
|
+
channel: '7',
|
74
|
+
authentication: ' 2',
|
75
|
+
payment_type: '',
|
76
|
+
filler: '' },
|
77
|
+
]
|
78
|
+
```
|
79
|
+
|
80
|
+
* There is methods to select just the Header, Trailer and Details registries This method will return a Cnab150::Registry. The detail method return any other registries diferent from Header and Trailer
|
81
|
+
|
82
|
+
```
|
83
|
+
> h = Cnab150.header(registries)
|
42
84
|
|
43
85
|
> h.registry_code
|
44
86
|
=> 'A'
|
45
87
|
|
46
88
|
> h.registry_type
|
47
89
|
=> '2'
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
* To change the keys to hash
|
94
|
+
```
|
95
|
+
> h = Cnab150.header(registries)
|
96
|
+
> h.to_hash
|
97
|
+
=> {:registry_code=>"A",
|
98
|
+
:registry_type=>"2",
|
99
|
+
:agreement=>"0000111111111",
|
100
|
+
:organization=>"PREF MUN XXXXXX-XYZ",
|
101
|
+
:bank_code=>"341",
|
102
|
+
:bank_name=>"BANCO ITAU S.A.",
|
103
|
+
:file_date=>"20151016",
|
104
|
+
:file_number=>"001312",
|
105
|
+
:version=>"03",
|
106
|
+
:service=>"",
|
107
|
+
:filler=>""}
|
108
|
+
```
|
48
109
|
|
49
|
-
|
50
|
-
#=> [
|
51
|
-
# { registry_code: 'A', registry_type: '2', agreement: '0000111111111', organization: 'PREF MUN XXXXXX-XYZ', bank_code: '341', bank_name: 'BANCO ITAU S.A.', file_date: '20151016', file_number: '001312', version: '03', service: '', filler: '' },
|
52
|
-
# { registry_code: 'G', account: '982300210019', payment_date: '20151015', credit_date: '20151016', barcode: '81660000000050924772015101600000000000000075', value: '000000000509', service_value: '0000080', registry_number: '31200007', agency: '0159', channel: '4', authentication: ' 2', payment_type: '', filler: '' },
|
53
|
-
# { registry_code: 'G', account: '982300210019', payment_date: '20151015', credit_date: '20151016', barcode: '81690000000230124772015103102012002302282001', value: '000000002301', service_value: '0000080', registry_number: '31200011', agency: '8347', channel: '7', authentication: ' 2', payment_type: '', filler: '' },
|
54
|
-
# { registry_code: 'Z', rows: '000004', total: '00000000001533612', filler: ' ' }
|
55
|
-
# ]
|
110
|
+
* To create a new layout add a YML file with the column names and positions
|
56
111
|
|
112
|
+
```
|
113
|
+
cnab150:
|
114
|
+
a:
|
115
|
+
registry_code: 1
|
116
|
+
registry_type: 1
|
117
|
+
agreement: 20
|
118
|
+
organization: 20
|
119
|
+
bank_code: 3
|
120
|
+
bank_name: 20
|
121
|
+
file_date: 8
|
122
|
+
file_number: 6
|
123
|
+
version: 2
|
124
|
+
service: 17
|
125
|
+
filler: 52
|
126
|
+
```
|
127
|
+
And override the default layout by setting the layout_path_file in the configure
|
128
|
+
|
129
|
+
```
|
130
|
+
Cnab150.configure do |config|
|
131
|
+
config.layout_file_path = 'absolute/path/to/your/layout.yml'
|
132
|
+
end
|
57
133
|
```
|
58
134
|
|
59
135
|
## Development
|
data/cnab150.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ['Marco Moura']
|
10
10
|
s.email = ['marco.moura@gmail.com']
|
11
11
|
|
12
|
-
s.summary = 'Return File CNAB 150.'
|
13
|
-
s.description = 'Return File CNAB 150.'
|
12
|
+
s.summary = 'Parser to Return File CNAB 150.'
|
13
|
+
s.description = 'Parser to Return File CNAB 150.'
|
14
14
|
s.homepage = 'https://github.com/marcomoura/cnab150'
|
15
15
|
|
16
16
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
data/config/layout.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
cnab150:
|
2
|
+
a:
|
3
|
+
registry_code: 1
|
4
|
+
registry_type: 1
|
5
|
+
agreement: 20
|
6
|
+
organization: 20
|
7
|
+
bank_code: 3
|
8
|
+
bank_name: 20
|
9
|
+
file_date: 8
|
10
|
+
file_number: 6
|
11
|
+
version: 2
|
12
|
+
service: 17
|
13
|
+
filler: 52
|
14
|
+
g:
|
15
|
+
registry_code: 1
|
16
|
+
account: 20
|
17
|
+
payment_date: 8
|
18
|
+
credit_date: 8
|
19
|
+
barcode: 44
|
20
|
+
value: 12
|
21
|
+
service_value: 7
|
22
|
+
registry_number: 8
|
23
|
+
agency: 4
|
24
|
+
channel: 1
|
25
|
+
authentication: 26
|
26
|
+
payment_type: 5
|
27
|
+
filler: 1
|
28
|
+
z:
|
29
|
+
registry_code: 1
|
30
|
+
rows: 6
|
31
|
+
total: 17
|
32
|
+
filler: 126
|
data/lib/cnab150.rb
CHANGED
@@ -1,44 +1,47 @@
|
|
1
|
-
require 'cnab150/
|
1
|
+
require 'cnab150/configuration'
|
2
2
|
require 'cnab150/registry'
|
3
3
|
require 'cnab150/parser'
|
4
4
|
require 'cnab150/layout'
|
5
5
|
require 'cnab150/errors'
|
6
|
+
require 'cnab150/version'
|
6
7
|
|
7
8
|
# The public interface of gem
|
8
9
|
module Cnab150
|
9
|
-
|
10
|
-
registries
|
11
|
-
|
10
|
+
class << self
|
11
|
+
def parse_registries(registries)
|
12
|
+
registries.each_with_object([]) do |r, a|
|
13
|
+
a << parse_registry(r)
|
14
|
+
end
|
12
15
|
end
|
13
|
-
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def parse_registry(registry)
|
18
|
+
type = Cnab150::Layout.build(registry.chars.first)
|
19
|
+
Cnab150::Registry.new(registry, type)
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
def header(registries)
|
23
|
+
find(registries, 'A')
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
def trailer(registries)
|
27
|
+
find(registries, 'Z')
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
def details(registries)
|
31
|
+
registries.select do |r|
|
32
|
+
!(r.registry_code.eql?('A') || r.registry_code.eql?('Z'))
|
33
|
+
end
|
31
34
|
end
|
32
|
-
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def select(type, raw)
|
37
|
+
registries = parse_registries(raw)
|
38
|
+
registries.select do |r|
|
39
|
+
r.registry_code.eql?(type.to_s.upcase)
|
40
|
+
end
|
38
41
|
end
|
39
|
-
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
+
def find(registries, type)
|
44
|
+
registries.find { |r| r.registry_code.eql?(type) }
|
45
|
+
end
|
43
46
|
end
|
44
47
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Cnab150 #:nodoc:
|
2
|
+
class << self
|
3
|
+
# Configures global settings
|
4
|
+
# Cnab150.configure do |config|
|
5
|
+
# config.default_per_page = 10
|
6
|
+
# end
|
7
|
+
def configure
|
8
|
+
yield(@config)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Global settings
|
12
|
+
def config
|
13
|
+
@config ||= Cnab150::Configuration.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Configuration #:nodoc:
|
18
|
+
attr_accessor :layout_file_path
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@layout_file_path = "#{File.dirname(__dir__)}/../config/layout.yml"
|
22
|
+
end
|
23
|
+
|
24
|
+
# The layouts method load the layouts from the yml file.
|
25
|
+
def layouts
|
26
|
+
@_ ||= YAML.load_file(@layout_file_path)['cnab150']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/cnab150/layout.rb
CHANGED
@@ -1,12 +1,25 @@
|
|
1
|
-
|
1
|
+
require 'yaml'
|
2
2
|
|
3
3
|
module Cnab150
|
4
4
|
# The Layout module is responsible of build the appropriate layout.
|
5
|
-
|
5
|
+
class Layout
|
6
6
|
def self.build(type)
|
7
|
-
Cnab150::
|
8
|
-
|
9
|
-
|
7
|
+
fail Cnab150::Errors::LayoutNotImplementedError unless
|
8
|
+
Cnab150.config.layouts.include?(type.downcase)
|
9
|
+
|
10
|
+
new Cnab150.config.layouts[type.downcase]
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(layout)
|
14
|
+
@layout = layout
|
15
|
+
end
|
16
|
+
|
17
|
+
def keys
|
18
|
+
@layout.keys.map(&:to_sym)
|
19
|
+
end
|
20
|
+
|
21
|
+
def layout
|
22
|
+
'A' + @layout.values.join('A')
|
10
23
|
end
|
11
24
|
end
|
12
25
|
end
|
data/lib/cnab150/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cnab150
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Moura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: Return File CNAB 150.
|
55
|
+
description: Parser to Return File CNAB 150.
|
56
56
|
email:
|
57
57
|
- marco.moura@gmail.com
|
58
58
|
executables: []
|
@@ -62,18 +62,18 @@ files:
|
|
62
62
|
- ".coveralls.yml"
|
63
63
|
- ".gitignore"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
68
69
|
- bin/console
|
69
70
|
- bin/setup
|
70
71
|
- cnab150.gemspec
|
72
|
+
- config/layout.yml
|
71
73
|
- lib/cnab150.rb
|
74
|
+
- lib/cnab150/configuration.rb
|
72
75
|
- lib/cnab150/errors.rb
|
73
76
|
- lib/cnab150/layout.rb
|
74
|
-
- lib/cnab150/layout/a.rb
|
75
|
-
- lib/cnab150/layout/g.rb
|
76
|
-
- lib/cnab150/layout/z.rb
|
77
77
|
- lib/cnab150/parser.rb
|
78
78
|
- lib/cnab150/registry.rb
|
79
79
|
- lib/cnab150/version.rb
|
@@ -99,5 +99,5 @@ rubyforge_project:
|
|
99
99
|
rubygems_version: 2.4.5.1
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
|
-
summary: Return File CNAB 150.
|
102
|
+
summary: Parser to Return File CNAB 150.
|
103
103
|
test_files: []
|
data/lib/cnab150/layout/a.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Cnab150
|
2
|
-
module Layout
|
3
|
-
# Layout of Register A
|
4
|
-
# This is a HEADER registry type
|
5
|
-
class A
|
6
|
-
def keys
|
7
|
-
[:registry_code, :registry_type, :agreement,
|
8
|
-
:organization, :bank_code, :bank_name,
|
9
|
-
:file_date, :file_number, :version,
|
10
|
-
:service, :filler]
|
11
|
-
end
|
12
|
-
|
13
|
-
def layout
|
14
|
-
'A' + [1, 1, 20, 20, 3, 20, 8, 6, 2, 17, 52].join('A')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/cnab150/layout/g.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Cnab150
|
2
|
-
module Layout
|
3
|
-
# Layout of Register G
|
4
|
-
# Return of collections identified by barcode
|
5
|
-
class G
|
6
|
-
def keys
|
7
|
-
[:registry_code, :account, :payment_date, :credit_date,
|
8
|
-
:barcode, :value, :service_value, :registry_number,
|
9
|
-
:agency, :channel, :authentication, :payment_type,
|
10
|
-
:filler]
|
11
|
-
end
|
12
|
-
|
13
|
-
def layout
|
14
|
-
'A' + [1, 20, 8, 8, 44, 12, 7, 8, 4, 1, 26, 5, 1].join('A')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/cnab150/layout/z.rb
DELETED