Class: AchClient::Sftp::AchBatch
- Inherits:
-
Abstract::AchBatch
- Object
- Abstract::AchBatch
- AchClient::Sftp::AchBatch
- Defined in:
- lib/ach_client/providers/sftp/ach_batch.rb
Overview
NACHA representation of an AchBatch
Instance Method Summary collapse
-
#batch_file_name ⇒ String
The filename used for the batch.
-
#cook_some_nachas ⇒ ACH::ACHFile
Converts this AchBatch into the NACHA object representation provided by the ACH gem.
-
#do_send_batch ⇒ Array<String>
Sends the batch to SFTP provider.
-
#initialize(ach_transactions: [], batch_number: nil) ⇒ AchBatch
constructor
A new instance of AchBatch.
Methods inherited from Abstract::AchBatch
Constructor Details
#initialize(ach_transactions: [], batch_number: nil) ⇒ AchBatch
Returns a new instance of AchBatch.
7 8 9 10 |
# File 'lib/ach_client/providers/sftp/ach_batch.rb', line 7 def initialize(ach_transactions: [], batch_number: nil) super(ach_transactions: ach_transactions) @batch_number = batch_number end |
Instance Method Details
#batch_file_name ⇒ String
The filename used for the batch
14 15 16 |
# File 'lib/ach_client/providers/sftp/ach_batch.rb', line 14 def batch_file_name self.class.module_parent.file_naming_strategy.(@batch_number) end |
#cook_some_nachas ⇒ ACH::ACHFile
Converts this AchBatch into the NACHA object representation provided by the ACH gem.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ach_client/providers/sftp/ach_batch.rb', line 34 def cook_some_nachas nacha = ACH::ACHFile.new nacha.instance_variable_set(:@header, nacha_file_header) # The NACHA can have multiple batches. # Transactions in the same batch must have the same originator and # sec_code, so we group by sec_code and originator when building batches @ach_transactions.group_by(&:sec_code).map do |sec_code, transactions| transactions.group_by(&:originator_name) .map do |originator_name, batch_transactions| batch_transactions.group_by(&:effective_entry_date) .map do |effective_entry_date, batched_transactions| nacha.batches << nacha_batch( sec_code, originator_name, effective_entry_date, batched_transactions ) end end end nacha end |
#do_send_batch ⇒ Array<String>
Sends the batch to SFTP provider
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ach_client/providers/sftp/ach_batch.rb', line 20 def do_send_batch self.class.module_parent.write_remote_file( file_path: File.join( self.class.module_parent.outgoing_path, batch_file_name ), file_body: cook_some_nachas.to_s ) @ach_transactions.map(&:external_ach_id) end |