guevara 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0ba03d076780de6b75d3ad0fb3a95936a56596d
4
- data.tar.gz: e7512da4cb5436b863fe87e41f73a35bb9b9581b
3
+ metadata.gz: f58362850aca1d07cc5f908b70c4ce191bb980e3
4
+ data.tar.gz: 09f73431c56f52808db6216c6a91b44318916139
5
5
  SHA512:
6
- metadata.gz: f80fbd6d4f56d080d024e8ecd7131f9e782d2c231ef388755006fbadd977f9db869a09c9034604e2fd56539df5553a6dee916c2f3279a003ec1430fdecac86fe
7
- data.tar.gz: 8901eadeb421a1bbd6bde04f78ebc16580c4181a4631812885b52cb5abacde7e9334686197354eabb13773655651a203d9e73c431b9b6ed6d7b1a65c202cde8c
6
+ metadata.gz: f9cf60939fd3f0ee3a4fd53945137011b434b1eb564f2af54967957d6639dac13ec4d916ff0cb0fd20ce90ed65c9217fb65b9d6c471d16988970f10a027e9327
7
+ data.tar.gz: 8762e796e63f6c1716b41ca44e4630fccee4fdff91e95e0a500e224549dfa285a4b18f31830a28e64fb9912c597fbfb124f1b37f00214376b5770783ea50074e
@@ -9,8 +9,8 @@ module Guevara
9
9
 
10
10
  attr_reader :transactions, :attributes
11
11
 
12
- def initialize(transactions, attributes)
13
- @transactions = transactions
12
+ def initialize(attributes)
13
+ @transactions = attributes.delete(:transactions)
14
14
  @attributes = attributes
15
15
  end
16
16
 
@@ -27,8 +27,7 @@ module Guevara
27
27
  end
28
28
 
29
29
  def batch_header
30
- header_attributes = { effective_date: effective_date }.merge(attributes)
31
- BatchHeader.new header_attributes
30
+ BatchHeader.new attributes
32
31
  end
33
32
 
34
33
  def batch_control
@@ -56,10 +55,6 @@ module Guevara
56
55
  modulo(1_000_000_000_000)
57
56
  end
58
57
 
59
- def effective_date
60
- transactions.first[:effective_date]
61
- end
62
-
63
58
  def entry transaction, index
64
59
  entry_attributes = transaction.merge(number: index + 1,
65
60
  origin_id: attributes[:origin_id])
@@ -16,8 +16,8 @@ module Guevara
16
16
  def fields
17
17
  ["1",
18
18
  "%<priority_code>02d",
19
- "%<destination_id>010d",
20
- "%<origin_id>010d",
19
+ " %<destination_id>09d",
20
+ " %<origin_id>09d",
21
21
  "%<created_at>10.10s",
22
22
  "%<id>1.1s",
23
23
  "094", # record size is fixed
@@ -14,9 +14,8 @@ module Guevara
14
14
 
15
15
  def batches= batches
16
16
  @batches = batches.each_with_index.map do |batch_attributes, index|
17
- transactions = batch_attributes.delete(:transactions)
18
17
  batch_attributes[:number] = index + 1
19
- Batch.new(transactions, batch_attributes)
18
+ Batch.new(batch_attributes)
20
19
  end
21
20
  end
22
21
 
@@ -42,7 +41,7 @@ module Guevara
42
41
  entry_count = total { |b| b.batch_control.attributes[:entry_count] }
43
42
  block_count = entry_count + batches.size * 2 + 2
44
43
  FileControl.new(
45
- batch_count: batches.size,
44
+ batch_count: batches.count,
46
45
  block_count: block_count,
47
46
  entry_count: entry_count,
48
47
  entry_hash: total { |b| b.batch_control.attributes[:entry_hash] },
@@ -1,3 +1,3 @@
1
1
  module Guevara
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -6,10 +6,7 @@ def sample_transaction
6
6
  id: 'FD00AFA8A0F7',
7
7
  type: 'debit',
8
8
  amount: 1600,
9
- effective_date: '2014-09-21',
10
9
  name: 'marge baker',
11
- first_name: 'marge',
12
- last_name: 'baker',
13
10
  additional_info: 'wellsville|KS|66092|101 2nd st|',
14
11
  telephone: '5858232966',
15
12
  account_type: 'checking',
@@ -18,6 +15,35 @@ def sample_transaction
18
15
  }
19
16
  end
20
17
 
18
+ def lines(nacha)
19
+ nacha.to_s.lines.to_a
20
+ end
21
+
22
+ def sample_batch
23
+ {
24
+ service_class: '200',
25
+ company_name: 'rubylit',
26
+ company_id: 'Ruby123',
27
+ company_date: '2014-09-18',
28
+ origin_id: '12345678',
29
+ effective_date: '2014-09-21',
30
+ transactions: [ sample_transaction ]
31
+ }
32
+ end
33
+
34
+ def sample_nacha
35
+ {
36
+ priority_code: 01,
37
+ destination_id: '12345678',
38
+ origin_id: '12345678',
39
+ created_at: '2014-11-28T13:30',
40
+ id: 'A',
41
+ destination_name: 'Rubylit',
42
+ origin_name: 'Zest',
43
+ batches: [ sample_batch ]
44
+ }
45
+ end
46
+
21
47
  def debugger_equal value, other
22
48
  flunk <<DEBUG unless value == other
23
49
  Output is not as Expected
@@ -2,13 +2,7 @@ require_relative 'helper.rb'
2
2
  require_relative '../lib/guevara/batch'
3
3
 
4
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
5
+ Guevara::Batch.new sample_batch.merge(:number => 1)
12
6
  end
13
7
 
14
8
  test 'generates the batch' do |batch|
@@ -1,43 +1,9 @@
1
1
  require_relative 'helper.rb'
2
2
  require 'guevara'
3
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
-
4
+ test 'generates nacha sample file' do |batch|
39
5
  expected = <<NACHA
40
- 101001234567800123456781411281330A094101 Rubylit Zest 0
6
+ 101 012345678 0123456781411281330A094101 Rubylit Zest 0
41
7
  5200rubylit Ruby123PPD 140918140921 1123456780000001
42
8
  6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
43
9
  705wellsville|KS|66092|101 2nd st| 00010000001
@@ -45,8 +11,26 @@ test 'generates the batch' do |batch|
45
11
  9000001000006000000020010310019000000001600000000000000
46
12
  NACHA
47
13
 
14
+ nacha = Guevara::Nacha.new sample_nacha
15
+
48
16
  nacha.to_s.lines.to_a.each_with_index do |line, index|
49
17
  debugger_equal line, expected.lines.to_a[index]
50
18
  end
19
+ end
20
+
21
+ test 'file control row gets the number of batches' do
22
+ nacha_attributes = sample_nacha.merge(:batches => [sample_batch, sample_batch])
23
+ nacha = Guevara::Nacha.new nacha_attributes
24
+
25
+ assert_equal lines(nacha).last[1,6].to_i, 2
26
+ end
27
+
28
+ test 'all the batches are added to the file' do
29
+ batches = 5.times.map do
30
+ sample_batch
31
+ end
32
+ nacha_attributes = sample_nacha.merge(:batches => batches)
51
33
 
34
+ nacha = Guevara::Nacha.new nacha_attributes
35
+ assert lines(nacha).size > 10
52
36
  end
@@ -15,7 +15,6 @@ end
15
15
 
16
16
  test 'generates a full file' do |header|
17
17
  debugger_equal header.to_s, <<NACHA
18
- 101001234567800123456781411281330A094101 Rubylit Zest 0
18
+ 101 012345678 0123456781411281330A094101 Rubylit Zest 0
19
19
  NACHA
20
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.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaston Ramos