ach 0.5.13 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bf3b5fe44c3ac5771d54dfce2a7c77df94106be4
4
- data.tar.gz: a0e34d9a38f43585eb7b606ab2f85db29780ed87
2
+ SHA256:
3
+ metadata.gz: c8950b0833382bb80f3ebf7b9e0e2702aece4ee0de2f385c4c9e5dbd4a7d1157
4
+ data.tar.gz: ce02f3a9a926be32cc72f8a986c308e4ceee7ceb617c487bc915ca20d6efa901
5
5
  SHA512:
6
- metadata.gz: 601060ec262bd2d580d4d32e9eadc721f4ceaa4e28cd261f6523b909fc4232ce1cb29b6c653e48bc9dbccc282cda68597ff1c93c40911648c4f9854d3a9135af
7
- data.tar.gz: 672e3d742549d701c449ed88c475bbeaed08c105d67d9538c052d8d2a3156edbc7199367fa36682c39e51d8893e144bbf367fa0229b47f697632386e16e3cebc
6
+ metadata.gz: 84465c6a64caeead398a541d7110ee473ce1cdd11a1c200a3b9f975813a2898e7d904ceaebc68e7d16cc5c880d9b27d5497f7930d5a28e8b7563038a9a3e1ede
7
+ data.tar.gz: dfc53a158083ef3559583b1f2e613f8fdd0f76ea38434345773d95af8875bc0d195b9ec560e1202cfcc8eeb742e1a923458fa0d052612132bcc57ec881f63c5b
data/lib/ach/ach_file.rb CHANGED
@@ -14,7 +14,7 @@ module ACH
14
14
  @control = Records::FileControl.new
15
15
 
16
16
  if data
17
- if (data.encode(Encoding.find('ASCII'),ENCODING_OPTIONS) =~ /\n|\r\n/).nil?
17
+ if (data.encode(Encoding.find('ASCII'), **ENCODING_OPTIONS) =~ /\n|\r\n/).nil?
18
18
  parse_fixed(data)
19
19
  else
20
20
  parse(data)
@@ -22,8 +22,9 @@ module ACH
22
22
  end
23
23
  end
24
24
 
25
+
25
26
  # @param eol [String] Line ending, default to CRLF
26
- def to_s eol = "\r\n"
27
+ def to_s eol = ACH.eol
27
28
  records = []
28
29
  records << @header
29
30
 
@@ -33,16 +34,14 @@ module ACH
33
34
  end
34
35
  records << @control
35
36
 
36
- records_count = records.inject(0) do |sum, record|
37
- sum + record.records_count
38
- end
39
-
37
+ records_count = records.map(&:records_count).reduce(:+)
40
38
  nines_needed = (10 - records_count) % 10
41
39
  nines_needed = nines_needed % 10
42
40
  nines_needed.times { records << Records::Nines.new() }
43
41
 
42
+ records_count = records.map(&:records_count).reduce(:+)
44
43
  @control.batch_count = @batches.length
45
- @control.block_count = (records.length / 10).ceil
44
+ @control.block_count = (records_count / 10).ceil
46
45
 
47
46
  @control.entry_count = 0
48
47
  @control.debit_total = 0
@@ -56,10 +55,10 @@ module ACH
56
55
  @control.entry_hash += batch.control.entry_hash
57
56
  end
58
57
 
59
- records.collect { |r| r.to_ach }.join(eol) + eol
58
+ records.collect { |r| r.to_ach(eol: eol) }.join(eol) + eol
60
59
  end
61
60
 
62
- def report
61
+ def report eol: ACH.eol
63
62
  to_s # To ensure correct records
64
63
  lines = []
65
64
 
@@ -75,7 +74,7 @@ module ACH
75
74
  lines << left_justify("Credit Total: ", 25) +
76
75
  sprintf("% 7d.%02d", @control.credit_total / 100, @control.credit_total % 100)
77
76
 
78
- lines.join("\r\n")
77
+ lines.join(eol)
79
78
  end
80
79
 
81
80
  def parse_fixed data
@@ -106,6 +105,7 @@ module ACH
106
105
  batch = ACH::Batch.new
107
106
  bh = batch.header
108
107
  bh.company_name = line[4..19].strip
108
+ bh.company_discretionary_data = line[20..39].strip
109
109
  bh.company_identification = line[40..49].gsub(/\A1/, '')
110
110
 
111
111
  # Does not try to guess if company identification is an EIN
@@ -146,7 +146,8 @@ module ACH
146
146
  when '8'
147
147
  # skip
148
148
  when '9'
149
- # skip
149
+ @control = Records::FileControl.new
150
+ @control.filler = line[55..93]
150
151
  else
151
152
  raise UnrecognizedTypeCode, "Didn't recognize type code #{type} for this line:\n#{line}"
152
153
  end
data/lib/ach/batch.rb CHANGED
@@ -14,7 +14,7 @@ module ACH
14
14
  end
15
15
 
16
16
  def to_ach
17
- @control.entry_count = @entries.inject(0) { |total, entry| total + entry.records_count }
17
+ @control.entry_count = @entries.map(&:records_count).reduce(:+).to_i
18
18
  @control.debit_total = 0
19
19
  @control.credit_total = 0
20
20
  @control.entry_hash = 0
@@ -51,8 +51,18 @@ module ACH
51
51
  @control.company_identification = @header.company_identification
52
52
  @control.originating_dfi_identification = @header.originating_dfi_identification
53
53
  @control.batch_number = @header.batch_number
54
+ if last_entry.is_a? ACH::BalancingEntryDetail
55
+ @control.credit_total = last_entry.amount
56
+ @control.debit_total = last_entry.amount
57
+ end
54
58
 
55
59
  [@header] + @entries + @addendas + [@control]
56
60
  end
61
+
62
+ private
63
+
64
+ def last_entry
65
+ @last_entry ||= @entries.last
66
+ end
57
67
  end
58
68
  end
@@ -53,7 +53,7 @@ module ACH
53
53
  if RUBY_VERSION < '1.9'
54
54
  val = Iconv.conv('ASCII//IGNORE', 'UTF8', val)
55
55
  else
56
- val = val.encode Encoding.find('ASCII'), ENCODING_OPTIONS
56
+ val = val.encode(Encoding.find('ASCII'), **ENCODING_OPTIONS)
57
57
  end
58
58
  end
59
59
 
@@ -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
@@ -85,4 +85,14 @@ module ACH::Records
85
85
  nil, nil, /\A\d{8}\z/
86
86
  field :trace_number, Integer, lambda { |f| sprintf('%07d', f)}
87
87
  end
88
+
89
+ class BalancingEntryDetail < EntryDetail
90
+ @fields = EntryDetail.fields.slice(0, 5)
91
+ const_field :individual_id_number, (' ' * 15)
92
+ field :account_description, String, lambda { |f| left_justify(f, 22)}
93
+ field :discretionary_data, String, lambda { |f| left_justify(f, 2)}, ' '
94
+ field :addenda_record_indicator, Integer, lambda { |f| sprintf('%01d', f)}, 0
95
+ field :origin_routing_number, String, lambda { |f| sprintf('%08d', f.to_i) }
96
+ field :trace_number, Integer, lambda { |f| sprintf('%07d', f)}
97
+ end
88
98
  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
data/lib/ach/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ACH
2
- VERSION = '0.5.13'.freeze
2
+ VERSION = '0.6.0'.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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ach
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.13
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Morgan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-04-07 00:00:00.000000000 Z
12
+ date: 2021-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: appraisal
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: 12.3.3
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: 12.3.3
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -125,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.5.2.3
128
+ rubygems_version: 3.0.3
130
129
  signing_key:
131
130
  specification_version: 4
132
131
  summary: Helper for building ACH files