diff --git a/.gitignore b/.gitignore index 1cc5e3a..d092dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ pkg *.gem install.log *.gemfile.lock +.idea diff --git a/Gemfile.lock b/Gemfile.lock index bfb66a9..e3b5fc9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,42 +1,42 @@ PATH remote: . specs: - ach (0.6.0) - holidays (>= 3.1) + ach (0.5.8.2) + holidays (>= 1.2.0, < 5.4.0) GEM remote: https://rubygems.org/ specs: - appraisal (2.2.0) + appraisal (2.5.0) bundler rake thor (>= 0.14.0) autotest (5.0.0) minitest-autotest (~> 1.0) - diff-lcs (1.3) - holidays (8.4.1) - minitest (5.14.1) + diff-lcs (1.5.0) + holidays (8.7.1) + minitest (5.20.0) minitest-autotest (1.1.1) minitest-server (~> 1.0) path_expander (~> 1.0) - minitest-server (1.0.6) - minitest (~> 5.0) + minitest-server (1.0.7) + minitest (~> 5.16) path_expander (1.1.0) - rake (13.0.1) + rake (13.1.0) rspec (3.9.0) rspec-core (~> 3.9.0) rspec-expectations (~> 3.9.0) rspec-mocks (~> 3.9.0) - rspec-core (3.9.2) + rspec-core (3.9.3) rspec-support (~> 3.9.3) - rspec-expectations (3.9.2) + rspec-expectations (3.9.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-support (3.9.3) - thor (1.0.1) + thor (1.3.0) PLATFORMS ruby @@ -51,4 +51,4 @@ DEPENDENCIES rspec (~> 3.2) BUNDLED WITH - 2.2.2 + 2.3.26 diff --git a/README.md b/README.md index 5ee5d2f..d962666 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,10 @@ # ACH -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. +ACH is a Ruby helper for building and parsing ACH files. -[![Build Status](https://travis-ci.org/jm81/ach.svg?branch=master)](https://travis-ci.org/jm81/ach) - -ach is a Ruby helper for builder ACH files. In particular, it helps with field +In particular, it helps with field order and alignment, and adds padding lines to end of file. -**This library has only been used in two production applications and for very -limited purposes. Please test thoroughly before using in a production -environment.** - -See [ACH::Builder](http://search.cpan.org/~tkeefer/ACH-Builder-0.03/lib/ACH/Builder.pm) -for a similar Perl library - ## Example You should consult a copy of the [ACH Rules](http://www.nacha.org) for details diff --git a/ach.gemspec b/ach.gemspec index 2508913..93c13d1 100644 --- a/ach.gemspec +++ b/ach.gemspec @@ -1,22 +1,33 @@ # -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) -require 'ach/version' +require "ach/version" Gem::Specification.new do |s| - s.name = 'ach' + s.name = "ach" s.version = ACH::VERSION.dup - s.summary = 'Helper for building ACH files' - s.description = 'ach is a Ruby helper for building and parsing ACH files. In particular, it helps with field order and alignment, and adds padding lines to end of file.' - s.email = 'jmorgan@morgancreative.net' - s.homepage = 'https://github.com/jm81/ach' - s.authors = ['Jared Morgan', 'Josh Puetz'] + s.summary = "Helper for building ACH files" + s.description = "ach is a Ruby helper for building and parsing ACH files. In particular, it helps with field order and alignment, and adds padding lines to end of file." + s.email = "henriquegasques@gmail.com" + s.homepage = "https://github.com/rubyritas/ach" + s.authors = ["Jared Morgan", "Josh Puetz"] + s.license = "MIT" - s.extra_rdoc_files = ['README.md'] + s.metadata = { + "bug_tracker_uri" => "https://github.com/rubyritas/ach/issues", + "changelog_uri" => "https://github.com/rubyritas/ach/blob/main/CHANGELOG.md", + "documentation_uri" => "https://github.com/rubyritas/ach/blob/main/README.md", + "homepage_uri" => "https://github.com/rubyritas/ach", + "source_code_uri" => "https://github.com/rubyritas/ach" + } + + s.extra_rdoc_files = ["README.md"] s.files = Dir.glob('lib/**/*') + %w{MIT-LICENSE README.md} s.test_files = Dir.glob('examples/**/*') s.require_path = 'lib' + s.required_ruby_version = ">= 2.0.0" + s.add_development_dependency('appraisal') s.add_development_dependency('autotest') s.add_development_dependency('rake', '>= 12.3.3') diff --git a/lib/ach/ach_file.rb b/lib/ach/ach_file.rb index 9a43a9e..1c0933e 100644 --- a/lib/ach/ach_file.rb +++ b/lib/ach/ach_file.rb @@ -27,21 +27,23 @@ def initialize data=nil def to_s eol = ACH.eol records = [] records << @header + addenda_entry_count = 0 @batches.each_with_index do |batch, index| batch.header.batch_number ||= index + 1 + addenda_entry_count += batch.entries.flat_map{|e| e.addenda}.length records += batch.to_ach end records << @control + total_length = addenda_entry_count + records.length - records_count = records.map(&:records_count).reduce(:+) - nines_needed = (10 - records_count) % 10 + nines_needed = 10 - (total_length % 10) nines_needed = nines_needed % 10 nines_needed.times { records << Records::Nines.new() } records_count = records.map(&:records_count).reduce(:+) @control.batch_count = @batches.length - @control.block_count = (records_count / 10).ceil + @control.block_count = ((records.length + addenda_entry_count) / 10).ceil @control.entry_count = 0 @control.debit_total = 0 @@ -79,7 +81,7 @@ def report eol: ACH.eol def parse_fixed data # replace with a space to preserve the record-lengths - encoded_data = data.encode(Encoding.find('ASCII'),{:invalid => :replace, :undef => :replace, :replace => ' '}) + encoded_data = data.encode(Encoding.find('ASCII'), **{:invalid => :replace, :undef => :replace, :replace => ' '}) parse encoded_data.scan(/.{94}/).join("\n") end @@ -166,7 +168,7 @@ def parse_descriptive_date(date_string) Date.today.to_datetime + (same_day_hour + same_day_minute/60) / 24 end - date_time || ACH::Data.parse(date_string) + date_time || Date.parse(date_string) rescue date_string end diff --git a/lib/ach/next_federal_reserve_effective_date.rb b/lib/ach/next_federal_reserve_effective_date.rb index 526ff3e..7123b75 100644 --- a/lib/ach/next_federal_reserve_effective_date.rb +++ b/lib/ach/next_federal_reserve_effective_date.rb @@ -6,7 +6,7 @@ class NextFederalReserveEffectiveDate if Gem.loaded_specs['holidays'].version < Gem::Version.new('7.0.0') :federal_reserve else - :federalreserve + :federalreservebanks end def initialize(submission_date) @submission_date = submission_date diff --git a/lib/ach/version.rb b/lib/ach/version.rb index 4a9b534..4441c33 100644 --- a/lib/ach/version.rb +++ b/lib/ach/version.rb @@ -1,3 +1,3 @@ module ACH - VERSION = '0.6.2'.freeze + VERSION = '0.5.8.2'.freeze end diff --git a/spec/ach/ach_file_spec.rb b/spec/ach/ach_file_spec.rb index 1d5a0f7..229bf0f 100644 --- a/spec/ach/ach_file_spec.rb +++ b/spec/ach/ach_file_spec.rb @@ -243,4 +243,4 @@ def add_balancing_entry_detail(batch) end end end -end +end \ No newline at end of file diff --git a/spec/ach/next_federal_reserve_effective_date_spec.rb b/spec/ach/next_federal_reserve_effective_date_spec.rb index b02a814..f50e837 100644 --- a/spec/ach/next_federal_reserve_effective_date_spec.rb +++ b/spec/ach/next_federal_reserve_effective_date_spec.rb @@ -36,6 +36,14 @@ end end + context 'when today is Thursday and tomorrow is a observed holiday' do + let(:run_date) { Date.new(2023, 11, 9) } + + it 'returns tomorrow' do + expect(subject).to eq(Date.new(2023, 11, 10)) + end + end + context 'when today is Monday and a holiday' do let(:run_date) { Date.new(2012, 5, 28) } diff --git a/spec/ach/parse_spec.rb b/spec/ach/parse_spec.rb index be2fcbf..9578567 100644 --- a/spec/ach/parse_spec.rb +++ b/spec/ach/parse_spec.rb @@ -21,6 +21,7 @@ it "should parse return/notification of change file" do fake_current_datetime = Date.new(2012, 10, 15) + expected_datetime = DateTime.new(2012, 10, 15, 19, 32) allow(Date).to receive(:today).and_return(fake_current_datetime) ach = ACH::ACHFile.new(@data) @@ -41,7 +42,7 @@ expect(bh.full_company_identification).to eq("1412345678") expect(bh.standard_entry_class_code).to eq('COR') expect(bh.company_entry_description).to eq("DESCRIPT") - expect(bh.company_descriptive_date).to eq('SD1932') + expect(bh.company_descriptive_date).to eq(expected_datetime) expect(bh.effective_entry_date).to eq(Date.parse('121015')) expect(bh.originating_dfi_identification).to eq("99222222") @@ -52,7 +53,7 @@ expect(bh.full_company_identification).to eq("1412345678") expect(bh.standard_entry_class_code).to eq('PPD') expect(bh.company_entry_description).to eq("DESCRIPT") - expect(bh.company_descriptive_date).to eq('121015') + expect(bh.company_descriptive_date).to eq(Date.parse('121015')) expect(bh.effective_entry_date).to eq(Date.parse('121015')) expect(bh.originating_dfi_identification).to eq("99222222")