guevara 0.0.1.pre.alpha.1 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +5 -0
- data/README.md +49 -2
- data/Rakefile +1 -1
- data/lib/guevara.rb +2 -2
- data/lib/guevara/addenda.rb +21 -0
- data/lib/guevara/batch.rb +65 -21
- data/lib/guevara/batch_control.rb +24 -0
- data/lib/guevara/batch_header.rb +33 -0
- data/lib/guevara/entry.rb +31 -0
- data/lib/guevara/file_control.rb +19 -0
- data/lib/guevara/file_header.rb +32 -0
- data/lib/guevara/nacha.rb +55 -0
- data/lib/guevara/row.rb +27 -0
- data/lib/guevara/version.rb +1 -1
- data/test/helper.rb +31 -0
- data/test/test_addenda.rb +12 -0
- data/test/test_batch_control.rb +21 -0
- data/test/test_batch_generation.rb +24 -0
- data/test/test_batch_header.rb +20 -0
- data/test/test_entry.rb +22 -0
- data/test/test_file_control.rb +18 -0
- data/test/test_file_generation.rb +52 -0
- data/test/test_file_header.rb +21 -0
- metadata +32 -7
- data/.ruby-version +0 -1
- data/test/batch_generation_test.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0ba03d076780de6b75d3ad0fb3a95936a56596d
|
4
|
+
data.tar.gz: e7512da4cb5436b863fe87e41f73a35bb9b9581b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f80fbd6d4f56d080d024e8ecd7131f9e782d2c231ef388755006fbadd977f9db869a09c9034604e2fd56539df5553a6dee916c2f3279a003ec1430fdecac86fe
|
7
|
+
data.tar.gz: 8901eadeb421a1bbd6bde04f78ebc16580c4181a4631812885b52cb5abacde7e9334686197354eabb13773655651a203d9e73c431b9b6ed6d7b1a65c202cde8c
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
[![Gem Version](http://img.shields.io/gem/v/guevara.svg)](http://badge.fury.io/rb/guevara)
|
2
|
+
[![Build Status](http://img.shields.io/travis/rubylit/guevara.svg)](https://travis-ci.org/rubylit/guevara)
|
3
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/rubylit/guevara.svg)](https://codeclimate.com/github/rubylit/guevara)
|
4
|
+
[![Inline docs](http://inch-ci.org/github/rubylit/guevara.png?branch=master)](http://inch-ci.org/github/rubylit/guevara)
|
5
|
+
|
1
6
|
# Guevara
|
2
7
|
|
3
8
|
Nacha file format is a pain, but with this gem the life will be easier
|
4
|
-
and the sun will shine for you :).
|
9
|
+
and the sun will shine for you :). [![Nacha Guevara](http://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Nacha_Guevara.jpg/289px-Nacha_Guevara.jpg)](http://es.wikipedia.org/wiki/Nacha_Guevara)
|
5
10
|
|
6
11
|
## Installation
|
7
12
|
|
@@ -9,7 +14,49 @@ and the sun will shine for you :).
|
|
9
14
|
|
10
15
|
## Usage
|
11
16
|
|
12
|
-
|
17
|
+
You need to build a big hash structure with all the required info,
|
18
|
+
create a `Guevara::Nacha` and call `to_s` to build the file.
|
19
|
+
|
20
|
+
~~~ruby
|
21
|
+
nacha = Guevara::Nacha.new(
|
22
|
+
priority_code: 01,
|
23
|
+
destination_id: '12345678',
|
24
|
+
origin_id: '12345678',
|
25
|
+
created_at: '2014-11-28T13:30',
|
26
|
+
id: 'A',
|
27
|
+
destination_name: 'Rubylit',
|
28
|
+
origin_name: 'Zest',
|
29
|
+
batches: [
|
30
|
+
{
|
31
|
+
service_class: '200',
|
32
|
+
company_name: 'rubylit',
|
33
|
+
company_id: 'Ruby123',
|
34
|
+
company_date: '2014-09-18',
|
35
|
+
origin_id: '12345678',
|
36
|
+
effective_date: '2014-09-21',
|
37
|
+
transactions: [{
|
38
|
+
id: 'FD00AFA8A0F7',
|
39
|
+
type: 'debit',
|
40
|
+
amount: 1600,
|
41
|
+
name: 'marge baker',
|
42
|
+
additional_info: 'wellsville|KS|66092|101 2nd st|',
|
43
|
+
telephone: '5858232966',
|
44
|
+
account_type: 'checking',
|
45
|
+
routing_number: 103100195,
|
46
|
+
account_number: '3ACCOUNT234'
|
47
|
+
}]
|
48
|
+
}
|
49
|
+
]
|
50
|
+
)
|
51
|
+
|
52
|
+
nacha.to_s #=>
|
53
|
+
# 101001234567800123456781411281330A094101 Rubylit Zest 0
|
54
|
+
# 5200rubylit Ruby123PPD 140918140921 1123456780000001
|
55
|
+
# 6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
|
56
|
+
# 705wellsville|KS|66092|101 2nd st| 00010000001
|
57
|
+
# 82000000020010310019000000001600000000000000 Ruby123 123456780000001
|
58
|
+
# 9000001000006000000020010310019000000001600000000000000
|
59
|
+
~~~
|
13
60
|
|
14
61
|
## Contributing
|
15
62
|
|
data/Rakefile
CHANGED
data/lib/guevara.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'row'
|
2
|
+
|
3
|
+
module Guevara
|
4
|
+
class Addenda < Row
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
{
|
8
|
+
number: 1 # we should not have more than 1 addenda
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def fields
|
13
|
+
["7", # row type
|
14
|
+
"05", # addenda type
|
15
|
+
"%<additional_info>-80.80s",
|
16
|
+
"%<number>04d",
|
17
|
+
"%<entry_number>07d"]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/guevara/batch.rb
CHANGED
@@ -1,30 +1,74 @@
|
|
1
|
+
require_relative 'batch_header'
|
2
|
+
require_relative 'batch_control'
|
3
|
+
require_relative 'addenda'
|
4
|
+
require_relative 'entry'
|
1
5
|
require 'date'
|
2
6
|
|
3
7
|
module Guevara
|
4
8
|
class Batch
|
5
9
|
|
6
|
-
attr_reader :
|
7
|
-
|
8
|
-
def initialize(transactions,
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@transactions = transactions
|
10
|
+
attr_reader :transactions, :attributes
|
11
|
+
|
12
|
+
def initialize(transactions, attributes)
|
13
|
+
@transactions = transactions
|
14
|
+
@attributes = attributes
|
12
15
|
end
|
13
|
-
|
16
|
+
|
14
17
|
def to_s
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
18
|
+
batch = []
|
19
|
+
|
20
|
+
batch << batch_header.to_s
|
21
|
+
transactions.each_with_index do |transaction, index|
|
22
|
+
batch << entry(transaction, index).to_s
|
23
|
+
batch << addenda(transaction, index).to_s
|
24
|
+
end
|
25
|
+
batch << batch_control
|
26
|
+
batch.join
|
27
|
+
end
|
28
|
+
|
29
|
+
def batch_header
|
30
|
+
header_attributes = { effective_date: effective_date }.merge(attributes)
|
31
|
+
BatchHeader.new header_attributes
|
32
|
+
end
|
33
|
+
|
34
|
+
def batch_control
|
35
|
+
control_attributes = {
|
36
|
+
entry_count: transactions.size * 2,
|
37
|
+
entry_hash: entry_hash,
|
38
|
+
total_debit: total('debit'),
|
39
|
+
total_credit: total('credit')
|
40
|
+
}.merge(attributes)
|
41
|
+
BatchControl.new control_attributes
|
42
|
+
end
|
43
|
+
|
44
|
+
def entry_hash
|
45
|
+
transactions.
|
46
|
+
map{ |t| t[:routing_number].to_i / 10 }. # ignore the check digit
|
47
|
+
reduce(:+). # sum
|
48
|
+
modulo(10_000_000_000) # cap to 10 digits
|
49
|
+
end
|
50
|
+
|
51
|
+
def total type
|
52
|
+
transactions.
|
53
|
+
select{ |t| t[:type] == type }.
|
54
|
+
map{ |t| t[:amount] }.
|
55
|
+
reduce(0, :+).
|
56
|
+
modulo(1_000_000_000_000)
|
57
|
+
end
|
58
|
+
|
26
59
|
def effective_date
|
27
|
-
|
28
|
-
end
|
29
|
-
|
60
|
+
transactions.first[:effective_date]
|
61
|
+
end
|
62
|
+
|
63
|
+
def entry transaction, index
|
64
|
+
entry_attributes = transaction.merge(number: index + 1,
|
65
|
+
origin_id: attributes[:origin_id])
|
66
|
+
Entry.new entry_attributes
|
67
|
+
end
|
68
|
+
|
69
|
+
def addenda transaction, index
|
70
|
+
Addenda.new transaction.merge(entry_number: index + 1)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
30
74
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'row'
|
2
|
+
|
3
|
+
module Guevara
|
4
|
+
class BatchControl < Row
|
5
|
+
|
6
|
+
def default_attributes
|
7
|
+
{ discretionary_data: '' }
|
8
|
+
end
|
9
|
+
|
10
|
+
def fields
|
11
|
+
["8",
|
12
|
+
"%<service_class>3d",
|
13
|
+
"%<entry_count>06d",
|
14
|
+
"%<entry_hash>010d",
|
15
|
+
"%<total_debit>012d",
|
16
|
+
"%<total_credit>012d",
|
17
|
+
"%<company_id>10.10s",
|
18
|
+
" " * 25, # Authentication and reserved fields.
|
19
|
+
"%<origin_id>8d",
|
20
|
+
"%<number>07d"]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'date'
|
2
|
+
require_relative 'row'
|
3
|
+
|
4
|
+
module Guevara
|
5
|
+
class BatchHeader < Row
|
6
|
+
|
7
|
+
def default_attributes
|
8
|
+
{ discretionary_data: '' }
|
9
|
+
end
|
10
|
+
|
11
|
+
def format_attributes
|
12
|
+
attributes[:company_date] = Date.parse(attributes[:company_date]).
|
13
|
+
strftime('%y%m%d')
|
14
|
+
attributes[:effective_date] = Date.parse(attributes[:effective_date]).
|
15
|
+
strftime('%y%m%d')
|
16
|
+
end
|
17
|
+
|
18
|
+
def fields
|
19
|
+
["5",
|
20
|
+
"%<service_class>3d",
|
21
|
+
"%<company_name>-16.16s",
|
22
|
+
"%<discretionary_data>-20.20s",
|
23
|
+
"%<company_id>10.10s",
|
24
|
+
"PPD ",
|
25
|
+
"%<company_date>s",
|
26
|
+
"%<effective_date>s",
|
27
|
+
" 1",
|
28
|
+
"%<origin_id>8d",
|
29
|
+
"%<number>07d"]
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'row'
|
2
|
+
|
3
|
+
module Guevara
|
4
|
+
class Entry < Row
|
5
|
+
|
6
|
+
ACCOUNT_TYPE_CODE = { 'checking' => '2', 'saving' => '3' }
|
7
|
+
TRANSACTION_TYPE_CODE = { 'credit' => '2', 'debit' => '7' }
|
8
|
+
|
9
|
+
def format_attributes
|
10
|
+
attributes[:transaction_code] ||= transaction_code
|
11
|
+
end
|
12
|
+
|
13
|
+
def fields
|
14
|
+
["6%<transaction_code>2d",
|
15
|
+
"%<routing_number>9d",
|
16
|
+
"%<account_number>-17.17s",
|
17
|
+
"%<amount>010d",
|
18
|
+
"%<id>-15.15s",
|
19
|
+
"%<name>-22.22s",
|
20
|
+
" 1", # Addenda record indicator
|
21
|
+
"%<origin_id>8d",
|
22
|
+
"%<number>07d"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def transaction_code
|
26
|
+
ACCOUNT_TYPE_CODE[attributes[:account_type]] +
|
27
|
+
TRANSACTION_TYPE_CODE[attributes[:type]]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'date'
|
2
|
+
require_relative 'row'
|
3
|
+
|
4
|
+
module Guevara
|
5
|
+
class FileControl < Row
|
6
|
+
|
7
|
+
def fields
|
8
|
+
["9",
|
9
|
+
"%<batch_count>06d",
|
10
|
+
"%<block_count>06d",
|
11
|
+
"%<entry_count>08d",
|
12
|
+
"%<entry_hash>010d",
|
13
|
+
"%<total_debit>012d",
|
14
|
+
"%<total_credit>012d",
|
15
|
+
" " * 39] # reserved
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'date'
|
2
|
+
require_relative 'row'
|
3
|
+
|
4
|
+
module Guevara
|
5
|
+
class FileHeader < Row
|
6
|
+
|
7
|
+
def default_attributes
|
8
|
+
{ reference: 0 }
|
9
|
+
end
|
10
|
+
|
11
|
+
def format_attributes
|
12
|
+
attributes[:created_at] = DateTime.parse(attributes[:created_at]).
|
13
|
+
strftime('%y%m%d%H%M')
|
14
|
+
end
|
15
|
+
|
16
|
+
def fields
|
17
|
+
["1",
|
18
|
+
"%<priority_code>02d",
|
19
|
+
"%<destination_id>010d",
|
20
|
+
"%<origin_id>010d",
|
21
|
+
"%<created_at>10.10s",
|
22
|
+
"%<id>1.1s",
|
23
|
+
"094", # record size is fixed
|
24
|
+
"10", # blocking factor
|
25
|
+
"1", # format code
|
26
|
+
"%<destination_name>23.23s",
|
27
|
+
"%<origin_name>23.23s",
|
28
|
+
"%<reference>8d"]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative 'file_header'
|
2
|
+
require_relative 'file_control'
|
3
|
+
require_relative 'batch'
|
4
|
+
|
5
|
+
module Guevara
|
6
|
+
class Nacha
|
7
|
+
|
8
|
+
attr_reader :attributes, :batches
|
9
|
+
|
10
|
+
def initialize attributes
|
11
|
+
self.batches = attributes.delete(:batches)
|
12
|
+
@attributes = attributes
|
13
|
+
end
|
14
|
+
|
15
|
+
def batches= batches
|
16
|
+
@batches = batches.each_with_index.map do |batch_attributes, index|
|
17
|
+
transactions = batch_attributes.delete(:transactions)
|
18
|
+
batch_attributes[:number] = index + 1
|
19
|
+
Batch.new(transactions, batch_attributes)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
file = []
|
25
|
+
file << file_header.to_s
|
26
|
+
batches.each { |batch| file << batch.to_s }
|
27
|
+
file << file_control.to_s
|
28
|
+
file.join('')
|
29
|
+
end
|
30
|
+
|
31
|
+
def file_header
|
32
|
+
FileHeader.new attributes
|
33
|
+
end
|
34
|
+
|
35
|
+
def total
|
36
|
+
batches.
|
37
|
+
map { |b| yield b }.
|
38
|
+
reduce(:+)
|
39
|
+
end
|
40
|
+
|
41
|
+
def file_control
|
42
|
+
entry_count = total { |b| b.batch_control.attributes[:entry_count] }
|
43
|
+
block_count = entry_count + batches.size * 2 + 2
|
44
|
+
FileControl.new(
|
45
|
+
batch_count: batches.size,
|
46
|
+
block_count: block_count,
|
47
|
+
entry_count: entry_count,
|
48
|
+
entry_hash: total { |b| b.batch_control.attributes[:entry_hash] },
|
49
|
+
total_debit: total { |b| b.total('debit') },
|
50
|
+
total_credit: total { |b| b.total('credit') }
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/lib/guevara/row.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Guevara
|
2
|
+
class Row
|
3
|
+
|
4
|
+
attr_reader :attributes
|
5
|
+
|
6
|
+
def initialize attributes
|
7
|
+
self.attributes = attributes
|
8
|
+
format_attributes
|
9
|
+
end
|
10
|
+
|
11
|
+
def attributes= attr
|
12
|
+
@attributes = default_attributes.merge(attr)
|
13
|
+
end
|
14
|
+
|
15
|
+
def format_attributes
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_attributes
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
format(fields.join, attributes) << "\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/guevara/version.rb
CHANGED
data/test/helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
lib_path = File.absolute_path(File.join(__FILE__, '..', '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include? lib_path
|
3
|
+
|
4
|
+
def sample_transaction
|
5
|
+
{
|
6
|
+
id: 'FD00AFA8A0F7',
|
7
|
+
type: 'debit',
|
8
|
+
amount: 1600,
|
9
|
+
effective_date: '2014-09-21',
|
10
|
+
name: 'marge baker',
|
11
|
+
first_name: 'marge',
|
12
|
+
last_name: 'baker',
|
13
|
+
additional_info: 'wellsville|KS|66092|101 2nd st|',
|
14
|
+
telephone: '5858232966',
|
15
|
+
account_type: 'checking',
|
16
|
+
routing_number: 103100195,
|
17
|
+
account_number: '3ACCOUNT234'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def debugger_equal value, other
|
22
|
+
flunk <<DEBUG unless value == other
|
23
|
+
Output is not as Expected
|
24
|
+
# #{ %w[ 0 1 2 3 4 5 6 7 8 9 ].map { |i| i.to_s * 10 }.join('')[1..-1] }
|
25
|
+
# #{ '1234567890' * 10 }
|
26
|
+
O#{ value.inspect }
|
27
|
+
E#{ other.inspect }
|
28
|
+
|
29
|
+
DEBUG
|
30
|
+
success
|
31
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative 'helper.rb'
|
2
|
+
require_relative '../lib/guevara/addenda'
|
3
|
+
|
4
|
+
test 'generates an addenda record' do
|
5
|
+
addenda = Guevara::Addenda.new({
|
6
|
+
additional_info: "wellsville|KS|66092|101 2nd st|",
|
7
|
+
entry_number: 1
|
8
|
+
}).to_s
|
9
|
+
debugger_equal addenda, <<NACHA
|
10
|
+
705wellsville|KS|66092|101 2nd st| 00010000001
|
11
|
+
NACHA
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'helper.rb'
|
2
|
+
require_relative '../lib/guevara/batch_control'
|
3
|
+
|
4
|
+
setup do
|
5
|
+
Guevara::BatchControl.new(
|
6
|
+
service_class: '200',
|
7
|
+
entry_count: 2,
|
8
|
+
entry_hash: 10310019,
|
9
|
+
total_debit: 1200,
|
10
|
+
total_credit: 3500,
|
11
|
+
company_id: 'Ruby123',
|
12
|
+
origin_id: '12345678',
|
13
|
+
number: 1
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'generates the batch contol row' do |batch_control|
|
18
|
+
debugger_equal batch_control.to_s, <<NACHA
|
19
|
+
82000000020010310019000000001200000000003500 Ruby123 123456780000001
|
20
|
+
NACHA
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'helper.rb'
|
2
|
+
require_relative '../lib/guevara/batch'
|
3
|
+
|
4
|
+
setup do
|
5
|
+
Guevara::Batch.new [ sample_transaction ],
|
6
|
+
service_class: '200',
|
7
|
+
company_name: 'rubylit',
|
8
|
+
company_id: 'Ruby123',
|
9
|
+
company_date: '2014-09-18',
|
10
|
+
origin_id: '12345678',
|
11
|
+
number: 1
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'generates the batch' do |batch|
|
15
|
+
expected = <<NACHA
|
16
|
+
5200rubylit Ruby123PPD 140918140921 1123456780000001
|
17
|
+
6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
|
18
|
+
705wellsville|KS|66092|101 2nd st| 00010000001
|
19
|
+
82000000020010310019000000001600000000000000 Ruby123 123456780000001
|
20
|
+
NACHA
|
21
|
+
batch.to_s.lines.to_a.each_with_index do |line, index|
|
22
|
+
debugger_equal line, expected.lines.to_a[index]
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'helper.rb'
|
2
|
+
require_relative '../lib/guevara/batch_header'
|
3
|
+
|
4
|
+
setup do
|
5
|
+
Guevara::BatchHeader.new(
|
6
|
+
service_class: '200',
|
7
|
+
company_name: 'rubylit',
|
8
|
+
company_id: '7654321',
|
9
|
+
company_date: '2014-09-18',
|
10
|
+
effective_date: '2014-09-21',
|
11
|
+
origin_id: '12345678',
|
12
|
+
number: 1
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'generates the batch header' do |batch_header|
|
17
|
+
debugger_equal batch_header.to_s, <<NACHA
|
18
|
+
5200rubylit 7654321PPD 140918140921 1123456780000001
|
19
|
+
NACHA
|
20
|
+
end
|
data/test/test_entry.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'helper.rb'
|
2
|
+
require_relative '../lib/guevara/entry'
|
3
|
+
|
4
|
+
setup do
|
5
|
+
Guevara::Entry.new(
|
6
|
+
type: 'debit',
|
7
|
+
account_type: 'checking',
|
8
|
+
routing_number: 103100195,
|
9
|
+
account_number: '3ACCOUNT234',
|
10
|
+
amount: 1600,
|
11
|
+
id: 'FD00AFA8A0F7',
|
12
|
+
name: 'marge baker',
|
13
|
+
origin_id: '12345678',
|
14
|
+
number: 1
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'generates the entry detail record' do |entry_record|
|
19
|
+
debugger_equal entry_record.to_s, <<NACHA
|
20
|
+
6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
|
21
|
+
NACHA
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'helper.rb'
|
2
|
+
require_relative '../lib/guevara/file_control'
|
3
|
+
|
4
|
+
test 'generates an file control' do
|
5
|
+
file_control = Guevara::FileControl.new(
|
6
|
+
batch_count: 2,
|
7
|
+
block_count: 8,
|
8
|
+
entry_count: 4,
|
9
|
+
entry_hash: 12249928,
|
10
|
+
total_debit: 12557,
|
11
|
+
total_credit: 0,
|
12
|
+
).to_s
|
13
|
+
debugger_equal file_control, <<NACHA
|
14
|
+
9000002000008000000040012249928000000012557000000000000
|
15
|
+
NACHA
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative 'helper.rb'
|
2
|
+
require 'guevara'
|
3
|
+
|
4
|
+
test 'generates the batch' do |batch|
|
5
|
+
|
6
|
+
transaction = {
|
7
|
+
id: 'FD00AFA8A0F7',
|
8
|
+
type: 'debit',
|
9
|
+
amount: 1600,
|
10
|
+
name: 'marge baker',
|
11
|
+
additional_info: 'wellsville|KS|66092|101 2nd st|',
|
12
|
+
telephone: '5858232966',
|
13
|
+
account_type: 'checking',
|
14
|
+
routing_number: 103100195,
|
15
|
+
account_number: '3ACCOUNT234'
|
16
|
+
}
|
17
|
+
|
18
|
+
batch = {
|
19
|
+
service_class: '200',
|
20
|
+
company_name: 'rubylit',
|
21
|
+
company_id: 'Ruby123',
|
22
|
+
company_date: '2014-09-18',
|
23
|
+
origin_id: '12345678',
|
24
|
+
effective_date: '2014-09-21',
|
25
|
+
transactions: [ transaction ]
|
26
|
+
}
|
27
|
+
|
28
|
+
nacha = Guevara::Nacha.new(
|
29
|
+
priority_code: 01,
|
30
|
+
destination_id: '12345678',
|
31
|
+
origin_id: '12345678',
|
32
|
+
created_at: '2014-11-28T13:30',
|
33
|
+
id: 'A',
|
34
|
+
destination_name: 'Rubylit',
|
35
|
+
origin_name: 'Zest',
|
36
|
+
batches: [ batch ]
|
37
|
+
)
|
38
|
+
|
39
|
+
expected = <<NACHA
|
40
|
+
101001234567800123456781411281330A094101 Rubylit Zest 0
|
41
|
+
5200rubylit Ruby123PPD 140918140921 1123456780000001
|
42
|
+
6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
|
43
|
+
705wellsville|KS|66092|101 2nd st| 00010000001
|
44
|
+
82000000020010310019000000001600000000000000 Ruby123 123456780000001
|
45
|
+
9000001000006000000020010310019000000001600000000000000
|
46
|
+
NACHA
|
47
|
+
|
48
|
+
nacha.to_s.lines.to_a.each_with_index do |line, index|
|
49
|
+
debugger_equal line, expected.lines.to_a[index]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'helper.rb'
|
2
|
+
require_relative '../lib/guevara/file_header'
|
3
|
+
|
4
|
+
setup do
|
5
|
+
Guevara::FileHeader.new(
|
6
|
+
priority_code: 01,
|
7
|
+
destination_id: '12345678',
|
8
|
+
origin_id: '12345678',
|
9
|
+
created_at: '2014-11-28T13:30',
|
10
|
+
id: 'A',
|
11
|
+
destination_name: 'Rubylit',
|
12
|
+
origin_name: 'Zest'
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'generates a full file' do |header|
|
17
|
+
debugger_equal header.to_s, <<NACHA
|
18
|
+
101001234567800123456781411281330A094101 Rubylit Zest 0
|
19
|
+
NACHA
|
20
|
+
end
|
21
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guevara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gaston Ramos
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -62,16 +62,32 @@ extensions: []
|
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
64
|
- ".gitignore"
|
65
|
-
- ".
|
65
|
+
- ".travis.yml"
|
66
66
|
- Gemfile
|
67
67
|
- LICENSE.txt
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
70
|
- guevara.gemspec
|
71
71
|
- lib/guevara.rb
|
72
|
+
- lib/guevara/addenda.rb
|
72
73
|
- lib/guevara/batch.rb
|
74
|
+
- lib/guevara/batch_control.rb
|
75
|
+
- lib/guevara/batch_header.rb
|
76
|
+
- lib/guevara/entry.rb
|
77
|
+
- lib/guevara/file_control.rb
|
78
|
+
- lib/guevara/file_header.rb
|
79
|
+
- lib/guevara/nacha.rb
|
80
|
+
- lib/guevara/row.rb
|
73
81
|
- lib/guevara/version.rb
|
74
|
-
- test/
|
82
|
+
- test/helper.rb
|
83
|
+
- test/test_addenda.rb
|
84
|
+
- test/test_batch_control.rb
|
85
|
+
- test/test_batch_generation.rb
|
86
|
+
- test/test_batch_header.rb
|
87
|
+
- test/test_entry.rb
|
88
|
+
- test/test_file_control.rb
|
89
|
+
- test/test_file_generation.rb
|
90
|
+
- test/test_file_header.rb
|
75
91
|
homepage: http://github.com/rubylit/guevara
|
76
92
|
licenses:
|
77
93
|
- GPL
|
@@ -87,9 +103,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
103
|
version: '0'
|
88
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
105
|
requirements:
|
90
|
-
- - "
|
106
|
+
- - ">="
|
91
107
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
108
|
+
version: '0'
|
93
109
|
requirements: []
|
94
110
|
rubyforge_project:
|
95
111
|
rubygems_version: 2.2.2
|
@@ -97,4 +113,13 @@ signing_key:
|
|
97
113
|
specification_version: 4
|
98
114
|
summary: Build nacha files.
|
99
115
|
test_files:
|
100
|
-
- test/
|
116
|
+
- test/helper.rb
|
117
|
+
- test/test_addenda.rb
|
118
|
+
- test/test_batch_control.rb
|
119
|
+
- test/test_batch_generation.rb
|
120
|
+
- test/test_batch_header.rb
|
121
|
+
- test/test_entry.rb
|
122
|
+
- test/test_file_control.rb
|
123
|
+
- test/test_file_generation.rb
|
124
|
+
- test/test_file_header.rb
|
125
|
+
has_rdoc:
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.2.0-dev
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require_relative '../lib/guevara/batch'
|
2
|
-
def sample_transaction
|
3
|
-
{
|
4
|
-
id: 'FD00AFA8A0F7',
|
5
|
-
type: 'debit',
|
6
|
-
amount: '1600',
|
7
|
-
effective_date: '2014-09-21',
|
8
|
-
first_name: 'marge',
|
9
|
-
last_name: 'baker',
|
10
|
-
address: '101 2nd st',
|
11
|
-
city: 'wellsville',
|
12
|
-
state: 'KS',
|
13
|
-
postal_code: '66092',
|
14
|
-
telephone: '5858232966',
|
15
|
-
account_type: 'checking',
|
16
|
-
routing_number: '103100195',
|
17
|
-
account_number: '3423423253234'
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def sample_options
|
22
|
-
{
|
23
|
-
:routing_number => '12345678',
|
24
|
-
:company_name => 'rubylit',
|
25
|
-
:company_id => 'Ruby123',
|
26
|
-
:date => '2014-09-18',
|
27
|
-
:index => 1
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
test 'generates the batch header' do
|
32
|
-
batch = Guevara::Batch.new [ sample_transaction ], sample_options
|
33
|
-
assert_equal batch.to_s.lines.to_a.first, <<NACHA
|
34
|
-
5200rubylit Ruby123PPD 140918140921 1123456780000001
|
35
|
-
NACHA
|
36
|
-
end
|