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 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'
@@ -1,6 +1,7 @@
1
1
  module ACH
2
2
  class Component
3
3
  include Validations
4
+ include Constants
4
5
 
5
6
  class UnknownAttribute < ArgumentError
6
7
  def initialize field
@@ -0,0 +1,7 @@
1
+ module ACH
2
+ module Constants
3
+ RECORD_SIZE = 94
4
+ BLOCKING_FACTOR = 10
5
+ FORMAT_CODE = 1
6
+ end
7
+ end
@@ -7,10 +7,10 @@ module ACH
7
7
  end
8
8
 
9
9
  def block_count
10
- (entry_count / 10.0).ceil
10
+ (file_entry_count.to_f / BLOCKING_FACTOR).ceil
11
11
  end
12
12
 
13
- def entry_count
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
- [header] + batches.map(&:to_ach).flatten + [control]
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
@@ -3,7 +3,7 @@ module ACH
3
3
  fields :record_type,
4
4
  :batch_count,
5
5
  :block_count,
6
- :entry_count,
6
+ :file_entry_count,
7
7
  :entry_hash,
8
8
  :total_debit_amount,
9
9
  :total_credit_amount,
@@ -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 => 94,
24
- :blocking_factor => 10,
25
- :format_code => 1,
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
@@ -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 => '->20',
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
- :entry_count => '->8',
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| val = val.to_s[0..length]; (transform ? val.send(transform) : val).send(padmethod, length, padstr) }
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
@@ -1,6 +1,7 @@
1
1
  module ACH
2
2
  class Record
3
3
  include Validations
4
+ include Constants
4
5
 
5
6
  class UnknownField < ArgumentError
6
7
  def initialize field, class_name
@@ -0,0 +1,6 @@
1
+ module ACH
2
+ class Tail < Record
3
+ fields :nines
4
+ defaults :nines => '9' * RECORD_SIZE
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module ACH
2
- VERSION = "0.0.1.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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'
@@ -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
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACH::Entry do
4
+ it "should have length of 94" do
5
+ ACH.sample_file.batch(0).entry(0).to_s!.length.should == ACH::Constants::RECORD_SIZE
6
+ end
7
+ end
@@ -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
 
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
- require File.expand_path(File.dirname(__FILE__) + '/../lib/ach.rb')
4
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/ach_builder.rb')
5
5
 
6
6
  RSpec.configure do |config|
7
7
  # some (optional) config here
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACH::Tail do
4
+ it "should have length of 94" do
5
+ ACH::Tail.new.to_s!.length.should == ACH::Constants::RECORD_SIZE
6
+ end
7
+ end
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.1.1
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: &81171620 !ruby/object:Gem::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: *81171620
24
+ version_requirements: *77088640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: active_support
27
- requirement: &81171160 !ruby/object:Gem::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: *81171160
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: