ach 0.5.16 → 0.6.1

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
  SHA256:
3
- metadata.gz: a6f2cdcb923998c4fc08e11bd9efeb320e349187e657ab7b29ff79c325447510
4
- data.tar.gz: 951a8528fb40feebb2ed689649b86cce1b25623a51fab780c0c6f994bfa8ffee
3
+ metadata.gz: 2675fc4115782f0d7fca900b070cebd739e9ceceee0c32d197b0ecd24e56f985
4
+ data.tar.gz: 3cb59f5617acdad57d7272124ca83999313c7675d48239a3cc0e510dcb095130
5
5
  SHA512:
6
- metadata.gz: 1bbc5ff04f7a5ee0196495e00c8a31077dc0a2ad1439953ff6c5c7971d2bb256ad03321261c187a8364c96ddfe6db0983104b07f10266ada86ad24699c09dab2
7
- data.tar.gz: 6d8158a6e81466d7d6017e4d017a948a898dfed6ed96880ff5b6be19cc4496890bd585da757d800dd921287e4334889d942d67390f7d020ebbefda9e2c69cbc8
6
+ metadata.gz: 8426fe5b8944fb11d7ca51bbc631a14f64e9e5dbd7ca668833905ac0f05b14c8f91248b4f43ff0c8245f705ec0b07e8588cb168ba82bb7160a880965414bbdfa
7
+ data.tar.gz: 5b403f8700e4ecc92f41f619f960455df6d88538f989ba3a545f28ff98632506dfeb76753622ff4d7ffbeecba71d91783110cb555cb4021097be9a71d2e9fdfd
data/README.md CHANGED
@@ -1,18 +1,20 @@
1
- #ACH
1
+ # ACH
2
+
3
+ Note: I'm no longer actively maintaining this gem, and would be happy to turn it over to someone else. Let me know if you'd like to take over.
2
4
 
3
5
  [![Build Status](https://travis-ci.org/jm81/ach.svg?branch=master)](https://travis-ci.org/jm81/ach)
4
6
 
5
7
  ach is a Ruby helper for builder ACH files. In particular, it helps with field
6
8
  order and alignment, and adds padding lines to end of file.
7
9
 
8
- **This library has only been used in one production application and for very
10
+ **This library has only been used in two production applications and for very
9
11
  limited purposes. Please test thoroughly before using in a production
10
12
  environment.**
11
13
 
12
14
  See [ACH::Builder](http://search.cpan.org/~tkeefer/ACH-Builder-0.03/lib/ACH/Builder.pm)
13
15
  for a similar Perl library
14
16
 
15
- ##Example
17
+ ## Example
16
18
 
17
19
  You should consult a copy of the [ACH Rules](http://www.nacha.org) for details
18
20
  on individual fields. You can probably obtain a copy from your bank.
@@ -30,6 +32,11 @@ fh.immediate_destination = '000000000'
30
32
  fh.immediate_destination_name = 'BANK NAME'
31
33
  fh.immediate_origin = '000000000'
32
34
  fh.immediate_origin_name = 'BANK NAME'
35
+ # Optional - This value is used in the File Creation Date/Time attributes - if excluded will default to Time.now
36
+ # Note that you may wish to modify the time zone here if your environment has a different time zone than the banks
37
+ # For example if your server is in UTC and the bank's is in US/Eastern, any files sent after 8pm Eastern/Midnight UTC
38
+ # would have a File Creation Date of the next day from the bank's perspective
39
+ fh.transmission_datetime = Time.now
33
40
 
34
41
  # Batch
35
42
  batch = ACH::Batch.new
@@ -38,7 +45,7 @@ bh.company_name = 'Company Name'
38
45
  bh.company_identification = '123456789' # Use 10 characters if you're not using an EIN
39
46
  bh.standard_entry_class_code = 'PPD'
40
47
  bh.company_entry_description = 'DESCRIPTION'
41
- bh.company_descriptive_date = Date.today
48
+ bh.company_descriptive_date = Date.today # Or string with 'SDHHMM' for same day ACH
42
49
  bh.effective_entry_date = ACH::NextFederalReserveEffectiveDate.new(Date.today).result
43
50
  bh.originating_dfi_identification = '00000000'
44
51
  ach.batches << batch
@@ -73,6 +80,6 @@ ach.batches.first.entries.first.addenda.first.payment_data
73
80
 
74
81
  **Note:** When adding an amount to your ach file, it needs to be in cents. So you'll want to multiply any dollar amounts by 100
75
82
 
76
- ##Copyright
83
+ ## Copyright
77
84
 
78
85
  Copyright (c) 2008-2009 Jared E Morgan, released under the MIT license
data/lib/ach/ach_file.rb CHANGED
@@ -24,7 +24,7 @@ module ACH
24
24
 
25
25
 
26
26
  # @param eol [String] Line ending, default to CRLF
27
- def to_s eol = "\r\n"
27
+ def to_s eol = ACH.eol
28
28
  records = []
29
29
  records << @header
30
30
 
@@ -55,10 +55,10 @@ module ACH
55
55
  @control.entry_hash += batch.control.entry_hash
56
56
  end
57
57
 
58
- records.collect { |r| r.to_ach }.join(eol) + eol
58
+ records.collect { |r| r.to_ach(eol: eol) }.join(eol) + eol
59
59
  end
60
60
 
61
- def report
61
+ def report eol: ACH.eol
62
62
  to_s # To ensure correct records
63
63
  lines = []
64
64
 
@@ -74,7 +74,7 @@ module ACH
74
74
  lines << left_justify("Credit Total: ", 25) +
75
75
  sprintf("% 7d.%02d", @control.credit_total / 100, @control.credit_total % 100)
76
76
 
77
- lines.join("\r\n")
77
+ lines.join(eol)
78
78
  end
79
79
 
80
80
  def parse_fixed data
@@ -105,6 +105,7 @@ module ACH
105
105
  batch = ACH::Batch.new
106
106
  bh = batch.header
107
107
  bh.company_name = line[4..19].strip
108
+ bh.company_discretionary_data = line[20..39].strip
108
109
  bh.company_identification = line[40..49].gsub(/\A1/, '')
109
110
 
110
111
  # Does not try to guess if company identification is an EIN
@@ -113,7 +114,7 @@ module ACH
113
114
  bh.full_company_identification = line[40..49]
114
115
  bh.standard_entry_class_code = line[50..52].strip
115
116
  bh.company_entry_description = line[53..62].strip
116
- bh.company_descriptive_date = Date.parse(line[63..68]) rescue nil # this can be various formats
117
+ bh.company_descriptive_date = parse_descriptive_date(line[63..68].strip)
117
118
  bh.effective_entry_date = Date.parse(line[69..74])
118
119
  bh.originating_dfi_identification = line[79..86].strip
119
120
  when '6'
@@ -145,7 +146,8 @@ module ACH
145
146
  when '8'
146
147
  # skip
147
148
  when '9'
148
- # skip
149
+ @control = Records::FileControl.new
150
+ @control.filler = line[55..93]
149
151
  else
150
152
  raise UnrecognizedTypeCode, "Didn't recognize type code #{type} for this line:\n#{line}"
151
153
  end
@@ -154,5 +156,19 @@ module ACH
154
156
  self.batches << batch unless batch.nil?
155
157
  to_s
156
158
  end
159
+
160
+ def parse_descriptive_date(date_string)
161
+ return if date_string.empty?
162
+
163
+ date_time = date_string.match(/^SD(\d{2})(\d{2})$/) do
164
+ same_day_hour, same_day_minute = _1.captures.map(&:to_f)
165
+
166
+ Date.today.to_datetime + (same_day_hour + same_day_minute/60) / 24
167
+ end
168
+
169
+ date_time || Data.parse(date_string)
170
+ rescue
171
+ date_string
172
+ end
157
173
  end
158
174
  end
data/lib/ach/batch.rb CHANGED
@@ -58,9 +58,9 @@ module ACH
58
58
 
59
59
  [@header] + @entries + @addendas + [@control]
60
60
  end
61
-
61
+
62
62
  private
63
-
63
+
64
64
  def last_entry
65
65
  @last_entry ||= @entries.last
66
66
  end
@@ -54,7 +54,7 @@ module ACH::Records
54
54
  return !self.addenda.empty?
55
55
  end
56
56
 
57
- def to_ach
57
+ def to_ach eol: ACH.eol
58
58
  self.addenda_record_indicator = (self.addenda.empty? ? 0 : 1) if self.respond_to?(:addenda_record_indicator)
59
59
  self.number_of_addenda_records = self.addenda.length if self.respond_to?(:number_of_addenda_records)
60
60
 
@@ -62,7 +62,7 @@ module ACH::Records
62
62
 
63
63
  self.addenda.each {|a|
64
64
  a.entry_detail_sequence_number = self.trace_number
65
- ach_string << "\r\n" + a.to_ach
65
+ ach_string << eol + a.to_ach
66
66
  }
67
67
  return ach_string
68
68
  end
@@ -1,17 +1,18 @@
1
1
  module ACH::Records
2
2
  class FileControl < Record
3
3
  @fields = []
4
-
4
+
5
5
  const_field :record_type, '9'
6
6
  # Many of the fields are calculated in ACHFile.to_ach
7
7
  field :batch_count, Integer, lambda { |f| sprintf('%06d', f)}
8
8
  field :block_count, Integer, lambda { |f| sprintf('%06d', f)}
9
9
  field :entry_count, Integer, lambda { |f| sprintf('%08d', f)}
10
10
  field :entry_hash, Integer, lambda { |f| sprintf('%010d', f % (10 ** 10))}
11
-
11
+
12
12
  field :debit_total, Integer, lambda { |f| sprintf('%012d', f)}
13
13
  field :credit_total, Integer, lambda { |f| sprintf('%012d', f)}
14
- const_field :reserved, (' ' * 39)
14
+
15
+ field :filler, String, lambda { |f| left_justify(f, 39)}, ' '
15
16
  end
16
17
  end
17
18
 
@@ -13,7 +13,7 @@ module ACH
13
13
 
14
14
  attr_accessor :case_sensitive
15
15
 
16
- def to_ach
16
+ def to_ach eol: nil
17
17
  to_ach = self.class.fields.collect { |f| send("#{f}_to_ach") }.join('')
18
18
  case_sensitive ? to_ach : to_ach.upcase
19
19
  end
@@ -3,7 +3,10 @@ module ACH
3
3
  # Passing in SD to the date signifies same-day to banks. This is used for the company_descriptive_date
4
4
  def self.stringify_with_same_day(f)
5
5
  return f.upcase if f.to_s.upcase.match(/^SD\d+$/)
6
- f.strftime('%y%m%d')
6
+
7
+ Date.strptime(f, '%y%m%d')
8
+ rescue
9
+ f
7
10
  end
8
11
  end
9
- end
12
+ end
data/lib/ach/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ACH
2
- VERSION = '0.5.16'.freeze
2
+ VERSION = '0.6.1'.freeze
3
3
  end
data/lib/ach.rb CHANGED
@@ -20,6 +20,12 @@ module ACH
20
20
  225, # ACH Debits Only
21
21
  280 # ACH Automated Accounting Advices
22
22
  ]
23
+
24
+ DEFAULT_EOL = "\r\n"
25
+
26
+ def self.eol
27
+ DEFAULT_EOL
28
+ end
23
29
  end
24
30
 
25
31
  require 'time'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ach
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.16
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Morgan
8
8
  - Josh Puetz
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-11-10 00:00:00.000000000 Z
12
+ date: 2023-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: appraisal
@@ -110,7 +110,7 @@ files:
110
110
  homepage: https://github.com/jm81/ach
111
111
  licenses: []
112
112
  metadata: {}
113
- post_install_message:
113
+ post_install_message:
114
114
  rdoc_options: []
115
115
  require_paths:
116
116
  - lib
@@ -125,8 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubygems_version: 3.0.3
129
- signing_key:
128
+ rubygems_version: 3.0.9
129
+ signing_key:
130
130
  specification_version: 4
131
131
  summary: Helper for building ACH files
132
132
  test_files: []