cnab150 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +9 -0
- data/.travis.yml +16 -0
- data/Gemfile +7 -0
- data/README.md +65 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/cnab150.gemspec +24 -0
- data/lib/cnab150.rb +37 -0
- data/lib/cnab150/errors.rb +6 -0
- data/lib/cnab150/layout.rb +12 -0
- data/lib/cnab150/layout/a.rb +18 -0
- data/lib/cnab150/layout/g.rb +18 -0
- data/lib/cnab150/layout/z.rb +15 -0
- data/lib/cnab150/parser.rb +21 -0
- data/lib/cnab150/registry.rb +30 -0
- data/lib/cnab150/version.rb +4 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0280fc4768cea08a6f5d6e5a9dcbdedc68bfb1b
|
4
|
+
data.tar.gz: 6603288d4ff5b9e48e0a829f4f2e9e47650ed3c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d27b8f6163578d1b224004edc1482f1879beb2ab0f1220defcb05cde5cce88444fe4961a3d54bd88b40fc936993cce2e1b831c70232ee8ee11050db446db185b
|
7
|
+
data.tar.gz: 77ab502df280ab5e28722ecc2e5432e63f283ba1058c4ab011f1c37bb7b5f37af04b194e5e710c15aee66aced758b3c19dcd330360ad416f8a05fa8088190bc7
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
rvm:
|
4
|
+
- 2.2.3
|
5
|
+
before_install: gem install bundler -v 1.10.6
|
6
|
+
|
7
|
+
script:
|
8
|
+
- bundle exec rake
|
9
|
+
- bundle exec rubocop
|
10
|
+
|
11
|
+
notifications:
|
12
|
+
email:
|
13
|
+
recipients:
|
14
|
+
- marco.moura@gmail.com
|
15
|
+
on_failure: change
|
16
|
+
on_success: never
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/marcomoura/cnab150.svg)](https://travis-ci.org/marcomoura/cnab150)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/marcomoura/cnab150/badge.svg?branch=master&service=github)](https://coveralls.io/github/marcomoura/cnab150?branch=master)
|
3
|
+
[![Code Climate](https://codeclimate.com/repos/562fd3b8e30ba04a3a00025f/badges/13ce3a3234d50e80222e/gpa.svg)](https://codeclimate.com/repos/562fd3b8e30ba04a3a00025f/feed)
|
4
|
+
[![Inline docs](http://inch-ci.org/github/marcomoura/cnab150.svg?branch=master)](http://inch-ci.org/github/marcomoura/cnab150)
|
5
|
+
|
6
|
+
# Cnab150
|
7
|
+
|
8
|
+
Client of cnab-150 return file.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'cnab150'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install cnab150
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
```
|
28
|
+
> registries = ['A20000111111111 PREF MUN XXXXXX-XYZ 341BANCO ITAU S.A. 2015101600131203 ',
|
29
|
+
> 'G982300210019 20151015201510168166000000005092477201510160000000000000007500000000050900000803120000701594 2 ',
|
30
|
+
> 'G982300210019 20151015201510168169000000023012477201510310201200230228200100000000230100000803120001183477 2 ',
|
31
|
+
> 'Z00000400000000001533612 ']
|
32
|
+
|
33
|
+
> cnabs = Cnab150.parse_registries(registries)
|
34
|
+
|
35
|
+
> h = Cnab150.header(cnabs)
|
36
|
+
|
37
|
+
> h.to_hash
|
38
|
+
=> {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: ''}
|
39
|
+
|
40
|
+
> h.registry_code
|
41
|
+
=> 'A'
|
42
|
+
|
43
|
+
> h.registry_type
|
44
|
+
=> '2'
|
45
|
+
|
46
|
+
> cnabs.to_hash
|
47
|
+
#=> [
|
48
|
+
# { 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: '' },
|
49
|
+
# { 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: '' },
|
50
|
+
# { 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: '' },
|
51
|
+
# { registry_code: 'Z', rows: '000004', total: '00000000001533612', filler: ' ' }
|
52
|
+
# ]
|
53
|
+
|
54
|
+
```
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
59
|
+
|
60
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marcomoura/cnab150.
|
65
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'cnab150'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/cnab150.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cnab150/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'cnab150'
|
8
|
+
s.version = Cnab150::VERSION
|
9
|
+
s.authors = ['Marco Moura']
|
10
|
+
s.email = ['marco.moura@gmail.com']
|
11
|
+
|
12
|
+
s.summary = 'Return File CNAB 150.'
|
13
|
+
s.description = 'Return File CNAB 150.'
|
14
|
+
s.homepage = "https://github.com/marcomoura/cnab150"
|
15
|
+
|
16
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
17
|
+
s.bindir = 'exe'
|
18
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
s.add_development_dependency 'bundler', '~> 1.10'
|
22
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
s.add_development_dependency 'rspec'
|
24
|
+
end
|
data/lib/cnab150.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'cnab150/version'
|
2
|
+
require 'cnab150/registry'
|
3
|
+
require 'cnab150/parser'
|
4
|
+
require 'cnab150/layout'
|
5
|
+
require 'cnab150/errors'
|
6
|
+
|
7
|
+
# The public interface of gem
|
8
|
+
module Cnab150
|
9
|
+
def self.parse_registries(registries)
|
10
|
+
registries.each_with_object([]) do |r, a|
|
11
|
+
a << parse_registry(r)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.parse_registry(registry)
|
16
|
+
type = Cnab150::Layout.build(registry.chars.first)
|
17
|
+
Cnab150::Registry.new(registry, type)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.header(registries)
|
21
|
+
find(registries, 'A')
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.trailer(registries)
|
25
|
+
find(registries, 'Z')
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.details(registries)
|
29
|
+
registries.select do |r|
|
30
|
+
!(r.registry_code.eql?('A') || r.registry_code.eql?('Z'))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.find(registries, type)
|
35
|
+
registries.find { |r| r.registry_code.eql?(type) }
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) + '/layout/*.rb'].each { |file| require file }
|
2
|
+
|
3
|
+
module Cnab150
|
4
|
+
# The Layout module is responsible of build the appropriate layout.
|
5
|
+
module Layout
|
6
|
+
def self.build(type)
|
7
|
+
Cnab150::Layout.const_get(type.upcase).new
|
8
|
+
rescue NameError
|
9
|
+
raise Cnab150::Errors::LayoutNotImplementedError
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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
|
@@ -0,0 +1,18 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Cnab150
|
2
|
+
# The Parser class is responsible to split up the string into a hash.
|
3
|
+
class Parser
|
4
|
+
def self.build(line, layout)
|
5
|
+
new(line, layout)
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(line, layout)
|
9
|
+
@line = line
|
10
|
+
@layout = layout
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_hash(keys)
|
14
|
+
Hash[keys.zip(to_a)]
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_a
|
18
|
+
@_process ||= @line.unpack(@layout)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Cnab150
|
2
|
+
# The Regisry class is responsible to transform the string into a object
|
3
|
+
# and is the public interface.
|
4
|
+
class Registry
|
5
|
+
def initialize(line, registry, parse = Cnab150::Parser)
|
6
|
+
@line = line
|
7
|
+
@registry = registry
|
8
|
+
@parse = parse
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_hash
|
12
|
+
@_r ||= values.to_hash(@registry.keys)
|
13
|
+
end
|
14
|
+
|
15
|
+
def raw
|
16
|
+
@line
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def values
|
22
|
+
@_v ||= @parse.build(@line, @registry.layout)
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(method)
|
26
|
+
return to_hash[method] if to_hash.key?(method.to_sym)
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cnab150
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marco Moura
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-30 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: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Return File CNAB 150.
|
56
|
+
email:
|
57
|
+
- marco.moura@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".coveralls.yml"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- cnab150.gemspec
|
71
|
+
- lib/cnab150.rb
|
72
|
+
- lib/cnab150/errors.rb
|
73
|
+
- lib/cnab150/layout.rb
|
74
|
+
- lib/cnab150/layout/a.rb
|
75
|
+
- lib/cnab150/layout/g.rb
|
76
|
+
- lib/cnab150/layout/z.rb
|
77
|
+
- lib/cnab150/parser.rb
|
78
|
+
- lib/cnab150/registry.rb
|
79
|
+
- lib/cnab150/version.rb
|
80
|
+
homepage: https://github.com/marcomoura/cnab150
|
81
|
+
licenses: []
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.5.1
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Return File CNAB 150.
|
103
|
+
test_files: []
|