Class: CanadaPayment::EFT::CPA005::Debit::File
- Inherits:
-
Object
- Object
- CanadaPayment::EFT::CPA005::Debit::File
- Includes:
- CanadaPayment::EFT::CPA005::Debit, Helper
- Defined in:
- lib/canada_payment/eft/cpa005/debit/file.rb
Constant Summary collapse
- DEFAULT_CURRENCY =
"CAD"- RECORD_LENGTH =
1464
Instance Attribute Summary collapse
-
#client_number ⇒ Object
readonly
Returns the value of attribute client_number.
-
#creation_date ⇒ Object
readonly
Returns the value of attribute creation_date.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#file_creation_number ⇒ Object
readonly
Returns the value of attribute file_creation_number.
-
#operating_subsidiary ⇒ Object
readonly
Returns the value of attribute operating_subsidiary.
-
#processing_centre ⇒ Object
readonly
Returns the value of attribute processing_centre.
-
#segments ⇒ Object
Returns the value of attribute segments.
-
#test ⇒ Object
Returns the value of attribute test.
Instance Method Summary collapse
- #add_segment(customer_name:, customer_number:, amount_cents:, payment_date:, institution:, transit:, account_number:, transaction_code: nil, client_short_name: nil, client_long_name: nil, client_sundry_info: nil, client_number: nil, operating_subsidiary: nil) ⇒ Object
- #basic_records ⇒ Object
- #file_output ⇒ Object
-
#header_record ⇒ Object
BASE CLASS OVERRIDES.
-
#initialize(client_number:, file_creation_number:, processing_centre:, operating_subsidiary: nil, creation_date: Date.Today, currency: DEFAULT_CURRENCY, test: false) ⇒ File
constructor
A new instance of File.
- #to_s ⇒ Object (also: #output)
- #trailer_record ⇒ Object
Methods included from Helper
#char_padded, #ensure_length, #padded_date, #space_padded, #zero_padded
Constructor Details
#initialize(client_number:, file_creation_number:, processing_centre:, operating_subsidiary: nil, creation_date: Date.Today, currency: DEFAULT_CURRENCY, test: false) ⇒ File
Returns a new instance of File.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 17 def initialize(client_number:, file_creation_number:, processing_centre:, operating_subsidiary: nil, creation_date: Date.Today, currency: DEFAULT_CURRENCY, test: false) @segments = [] @client_number = client_number @operating_subsidiary = @file_creation_number = file_creation_number @creation_date = creation_date @processing_centre = processing_centre @currency = currency.upcase @test = test end |
Instance Attribute Details
#client_number ⇒ Object (readonly)
Returns the value of attribute client_number.
10 11 12 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 10 def client_number @client_number end |
#creation_date ⇒ Object (readonly)
Returns the value of attribute creation_date.
10 11 12 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 10 def creation_date @creation_date end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
10 11 12 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 10 def currency @currency end |
#file_creation_number ⇒ Object (readonly)
Returns the value of attribute file_creation_number.
10 11 12 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 10 def file_creation_number @file_creation_number end |
#operating_subsidiary ⇒ Object (readonly)
Returns the value of attribute operating_subsidiary.
10 11 12 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 10 def @operating_subsidiary end |
#processing_centre ⇒ Object (readonly)
Returns the value of attribute processing_centre.
10 11 12 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 10 def processing_centre @processing_centre end |
#segments ⇒ Object
Returns the value of attribute segments.
9 10 11 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 9 def segments @segments end |
#test ⇒ Object
Returns the value of attribute test.
9 10 11 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 9 def test @test end |
Instance Method Details
#add_segment(customer_name:, customer_number:, amount_cents:, payment_date:, institution:, transit:, account_number:, transaction_code: nil, client_short_name: nil, client_long_name: nil, client_sundry_info: nil, client_number: nil, operating_subsidiary: nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 61 def add_segment(customer_name:, customer_number:, amount_cents:, payment_date:, institution:, transit:, account_number:, transaction_code: nil, client_short_name: nil, client_long_name: nil, client_sundry_info: nil, client_number: nil, operating_subsidiary: nil) client_number ||= @client_number ||= @operating_subsidiary client_short_name ||= @client_short_name client_long_name ||= @client_long_name segment = Segment.new customer_name: customer_name, customer_number: customer_number, amount_cents: amount_cents, payment_date: payment_date, institution: institution, transit: transit, account_number: account_number, transaction_code: transaction_code, client_short_name: client_short_name, client_long_name: client_long_name, client_sundry_info: client_sundry_info, client_number: client_number, operating_subsidiary: @segments << segment segment end |
#basic_records ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 89 def basic_records output = [] segments.each_with_index do |segment, i| output << '' if output[-1].nil? || output[-1].length == RECORD_LENGTH # add record header if i % 6 == 0 record_number = (i / 6) + 2 output[-1] += "D" + zero_padded(record_number, 9) + client_number_with_subsidiary + formatted_file_creation_number end output[-1] += segment.to_s end # fill last row with blank segments unless output[-1].nil? while output[-1].length < RECORD_LENGTH output[-1] += Segment.blank_values end end output end |
#file_output ⇒ Object
34 35 36 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 34 def file_output header_record + line_records end |
#header_record ⇒ Object
BASE CLASS OVERRIDES
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 39 def header_record 'A' + zero_padded('1', 9) + client_number_with_subsidiary + formatted_file_creation_number + file_creation_date + zero_padded(processing_centre, 5) + space_padded(nil, 20) + ensure_length(currency, 3).upcase + space_padded(nil, 1406) end |
#to_s ⇒ Object Also known as: output
115 116 117 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 115 def to_s header_record + "\n" + basic_records.join("\n") + "\n" + trailer_record end |
#trailer_record ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/canada_payment/eft/cpa005/debit/file.rb', line 51 def trailer_record 'Z' + zero_padded(trailer_record_number, 9) + client_number_with_subsidiary + formatted_file_creation_number + zero_padded(total_amount_cents, 14) + zero_padded(@segments.size, 8) + zero_padded(nil, 1418) end |