ach_builder 0.0.1.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/ach/component.rb +1 -0
- data/lib/ach/constants.rb +7 -0
- data/lib/ach/file.rb +10 -4
- data/lib/ach/file/control.rb +1 -1
- data/lib/ach/file/header.rb +3 -3
- data/lib/ach/formatter.rb +8 -4
- data/lib/ach/record.rb +1 -0
- data/lib/ach/tail.rb +6 -0
- data/lib/ach/version.rb +1 -1
- data/lib/ach_builder.rb +2 -0
- data/spec/batch_spec.rb +10 -0
- data/spec/entry_spec.rb +7 -0
- data/spec/file_spec.rb +17 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/tail_spec.rb +7 -0
- metadata +9 -5
data/README.md
CHANGED
@@ -13,7 +13,7 @@ with similar functionality
|
|
13
13
|
##Example
|
14
14
|
# attributes for records may be passed as parameters, as well as modified in block
|
15
15
|
# these attributes will be passed to all inner entities in a cascade way, if required
|
16
|
-
file = File.new(:company_id => '11-11111', :company_name => 'MY COMPANY') do
|
16
|
+
file = ACH::File.new(:company_id => '11-11111', :company_name => 'MY COMPANY') do
|
17
17
|
immediate_dest_name 'COMMERCE BANK'
|
18
18
|
immediate_origin '123123123'
|
19
19
|
immediate_oreigin_name 'MYCOMPANY'
|
data/lib/ach/component.rb
CHANGED
data/lib/ach/file.rb
CHANGED
@@ -7,10 +7,10 @@ module ACH
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def block_count
|
10
|
-
(
|
10
|
+
(file_entry_count.to_f / BLOCKING_FACTOR).ceil
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def file_entry_count
|
14
14
|
batches.map{ |b| b.entries.length }.inject(&:+) || 0
|
15
15
|
end
|
16
16
|
|
@@ -27,11 +27,17 @@ module ACH
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def to_ach
|
30
|
-
|
30
|
+
extra = block_count * BLOCKING_FACTOR - file_entry_count
|
31
|
+
tail = ([Tail.new] * extra).unshift(control)
|
32
|
+
[header] + batches.map(&:to_ach).flatten + tail
|
31
33
|
end
|
32
34
|
|
33
35
|
def to_s!
|
34
|
-
to_ach.map(&:to_s!).join("\n")
|
36
|
+
to_ach.map(&:to_s!).join("\r\n") + "\r\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
def record_count
|
40
|
+
2 + batches.length * 2 + file_entry_count
|
35
41
|
end
|
36
42
|
|
37
43
|
def write filename
|
data/lib/ach/file/control.rb
CHANGED
data/lib/ach/file/header.rb
CHANGED
@@ -20,9 +20,9 @@ module ACH
|
|
20
20
|
:date => lambda{ Time.now.strftime("%y%m%d") },
|
21
21
|
:time => lambda{ Time.now.strftime("%H%M") },
|
22
22
|
:file_id_modifier => 'A',
|
23
|
-
:record_size =>
|
24
|
-
:blocking_factor =>
|
25
|
-
:format_code =>
|
23
|
+
:record_size => RECORD_SIZE,
|
24
|
+
:blocking_factor => BLOCKING_FACTOR,
|
25
|
+
:format_code => FORMAT_CODE,
|
26
26
|
:reference_code => ''
|
27
27
|
end
|
28
28
|
end
|
data/lib/ach/formatter.rb
CHANGED
@@ -22,7 +22,7 @@ module ACH
|
|
22
22
|
:time => '<-4',
|
23
23
|
:file_id_modifier => '<-1|upcase',
|
24
24
|
:record_size => '->3',
|
25
|
-
:blocking_factor => '->
|
25
|
+
:blocking_factor => '->2',
|
26
26
|
:format_code => '<-1',
|
27
27
|
:immediate_dest_name => '<-23',
|
28
28
|
:immediate_origin_name => '<-23',
|
@@ -46,8 +46,9 @@ module ACH
|
|
46
46
|
:bank_6 => '<-6',
|
47
47
|
:batch_count => '->6',
|
48
48
|
:block_count => '->6',
|
49
|
-
:
|
50
|
-
:bank_39 => '<-39'
|
49
|
+
:file_entry_count => '->8',
|
50
|
+
:bank_39 => '<-39',
|
51
|
+
:nines => '<-94'
|
51
52
|
}.freeze
|
52
53
|
|
53
54
|
RULE_PARSER_REGEX = /^(<-|->)(\d+)(-)?(\|\w+)?$/
|
@@ -73,7 +74,10 @@ module ACH
|
|
73
74
|
length = width.to_i
|
74
75
|
padstr = padmethod == :ljust ? ' ' : pad == '-' ? ' ' : '0'
|
75
76
|
transform = transf[1..-1] if transf
|
76
|
-
@@compiled_rules[field_name] = lambda{ |val|
|
77
|
+
@@compiled_rules[field_name] = lambda{ |val|
|
78
|
+
val = val.to_s[0..length]
|
79
|
+
(transform ? val.send(transform) : val).send(padmethod, length, padstr)
|
80
|
+
}
|
77
81
|
end
|
78
82
|
private :compile_rule
|
79
83
|
end
|
data/lib/ach/record.rb
CHANGED
data/lib/ach/tail.rb
ADDED
data/lib/ach/version.rb
CHANGED
data/lib/ach_builder.rb
CHANGED
@@ -3,11 +3,13 @@ require 'active_support/ordered_hash'
|
|
3
3
|
|
4
4
|
require "ach/version"
|
5
5
|
|
6
|
+
require 'ach/constants'
|
6
7
|
require 'ach/formatter'
|
7
8
|
require 'ach/validations'
|
8
9
|
require 'ach/component'
|
9
10
|
require 'ach/record'
|
10
11
|
require 'ach/entry'
|
12
|
+
require 'ach/tail'
|
11
13
|
require 'ach/batch'
|
12
14
|
require 'ach/batch/header'
|
13
15
|
require 'ach/batch/control'
|
data/spec/batch_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe ACH::Batch do
|
4
4
|
before(:each) do
|
5
5
|
@batch = ACH::Batch.new
|
6
|
+
@file = ACH.sample_file
|
6
7
|
end
|
7
8
|
|
8
9
|
it "should create entry with attributes" do
|
@@ -48,4 +49,13 @@ describe ACH::Batch do
|
|
48
49
|
@batch.entry :amount => 100, :transaction_code => 21
|
49
50
|
@batch.header.service_class_code.should == 200
|
50
51
|
end
|
52
|
+
|
53
|
+
it "should have header record with length of 94" do
|
54
|
+
@file.batch(0).header.to_s!.length.should == ACH::Constants::RECORD_SIZE
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have control record with length of 94" do
|
58
|
+
@file.batch(0).send(:before_header) # to fill service_class_code value
|
59
|
+
@file.batch(0).control.to_s!.length.should == ACH::Constants::RECORD_SIZE
|
60
|
+
end
|
51
61
|
end
|
data/spec/entry_spec.rb
ADDED
data/spec/file_spec.rb
CHANGED
@@ -14,6 +14,7 @@ describe ACH::File do
|
|
14
14
|
@file_with_batch = ACH::File.new(@attributes) do
|
15
15
|
batch :entry_class_code => 'WEB'
|
16
16
|
end
|
17
|
+
@sample_file = ACH.sample_file
|
17
18
|
end
|
18
19
|
|
19
20
|
it "should correctly assign attributes" do
|
@@ -69,5 +70,21 @@ describe ACH::File do
|
|
69
70
|
batch = @file_with_batch.batch(0)
|
70
71
|
batch.attributes.should include(@file_with_batch.attributes)
|
71
72
|
end
|
73
|
+
|
74
|
+
it "should have correct record count" do
|
75
|
+
@sample_file.record_count.should == 8
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should have header record with length of 94" do
|
79
|
+
@sample_file.header.to_s!.length.should == ACH::Constants::RECORD_SIZE
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should have control record with length of 94" do
|
83
|
+
@sample_file.control.to_s!.length.should == ACH::Constants::RECORD_SIZE
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should have length devisible by 94 (record size)" do
|
87
|
+
(@sample_file.to_s!.gsub("\r\n", '').length % ACH::Constants::RECORD_SIZE).should be_zero
|
88
|
+
end
|
72
89
|
end
|
73
90
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/tail_spec.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ach_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-14 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &77088640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *77088640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: active_support
|
27
|
-
requirement: &
|
27
|
+
requirement: &77088380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 2.3.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *77088380
|
36
36
|
description: Ruby tools for building ACH (Automated Clearing House) files
|
37
37
|
email:
|
38
38
|
- a.kuzko@gmail.com
|
@@ -51,20 +51,24 @@ files:
|
|
51
51
|
- lib/ach/batch/control.rb
|
52
52
|
- lib/ach/batch/header.rb
|
53
53
|
- lib/ach/component.rb
|
54
|
+
- lib/ach/constants.rb
|
54
55
|
- lib/ach/entry.rb
|
55
56
|
- lib/ach/file.rb
|
56
57
|
- lib/ach/file/control.rb
|
57
58
|
- lib/ach/file/header.rb
|
58
59
|
- lib/ach/formatter.rb
|
59
60
|
- lib/ach/record.rb
|
61
|
+
- lib/ach/tail.rb
|
60
62
|
- lib/ach/validations.rb
|
61
63
|
- lib/ach/version.rb
|
62
64
|
- lib/ach_builder.rb
|
63
65
|
- spec/batch_spec.rb
|
66
|
+
- spec/entry_spec.rb
|
64
67
|
- spec/file_spec.rb
|
65
68
|
- spec/formatter_spec.rb
|
66
69
|
- spec/record_spec.rb
|
67
70
|
- spec/spec_helper.rb
|
71
|
+
- spec/tail_spec.rb
|
68
72
|
homepage: http://github.com/akuzko/ach_builder
|
69
73
|
licenses: []
|
70
74
|
post_install_message:
|