Class: Aba::Batch
Constant Summary
Constants included from Validations
Validations::BECS_PATTERN, Validations::CREDIT_TRANSACTION_CODES, Validations::DEBIT_TRANSACTION_CODES, Validations::INDICATORS
Instance Attribute Summary collapse
-
#bsb ⇒ Object
Returns the value of attribute bsb.
-
#description ⇒ Object
Returns the value of attribute description.
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#financial_institution ⇒ Object
Returns the value of attribute financial_institution.
-
#process_at ⇒ Object
Returns the value of attribute process_at.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Attributes included from Validations
Instance Method Summary collapse
- #add_return(attrs = {}) ⇒ Object
- #add_transaction(attrs = {}) ⇒ Object
- #errors ⇒ Object
-
#initialize(attrs = {}, transactions = []) {|_self| ... } ⇒ Batch
constructor
A new instance of Batch.
- #to_s ⇒ Object
- #transactions ⇒ Object
- #transactions_valid? ⇒ Boolean
- #valid? ⇒ Boolean
Methods included from Validations
Constructor Details
#initialize(attrs = {}, transactions = []) {|_self| ... } ⇒ Batch
Returns a new instance of Batch.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aba/batch.rb', line 37 def initialize(attrs = {}, transactions = []) attrs.each do |key, value| send("#{key}=", value) end @entries = [] unless transactions.nil? || transactions.empty? transactions.to_a.each do |t| self.add_transaction(t) unless t.nil? || t.empty? end end yield self if block_given? end |
Instance Attribute Details
#bsb ⇒ Object
Returns the value of attribute bsb.
7 8 9 |
# File 'lib/aba/batch.rb', line 7 def bsb @bsb end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/aba/batch.rb', line 7 def description @description end |
#entries ⇒ Object
Returns the value of attribute entries.
7 8 9 |
# File 'lib/aba/batch.rb', line 7 def entries @entries end |
#financial_institution ⇒ Object
Returns the value of attribute financial_institution.
7 8 9 |
# File 'lib/aba/batch.rb', line 7 def financial_institution @financial_institution end |
#process_at ⇒ Object
Returns the value of attribute process_at.
7 8 9 |
# File 'lib/aba/batch.rb', line 7 def process_at @process_at end |
#user_id ⇒ Object
Returns the value of attribute user_id.
7 8 9 |
# File 'lib/aba/batch.rb', line 7 def user_id @user_id end |
#user_name ⇒ Object
Returns the value of attribute user_name.
7 8 9 |
# File 'lib/aba/batch.rb', line 7 def user_name @user_name end |
Instance Method Details
#add_return(attrs = {}) ⇒ Object
71 72 73 |
# File 'lib/aba/batch.rb', line 71 def add_return(attrs = {}) add_entry(Aba::Return, attrs) end |
#add_transaction(attrs = {}) ⇒ Object
67 68 69 |
# File 'lib/aba/batch.rb', line 67 def add_transaction(attrs = {}) add_entry(Aba::Transaction, attrs) end |
#errors ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/aba/batch.rb', line 87 def errors # Run validations has_errors? has_entry_errors? # Build errors all_errors = {} all_errors[:aba] = self.error_collection unless self.error_collection.empty? entry_error_collection = entries.each_with_index .map { |t, i| [i, t.error_collection] } .reject { |e| e[1].nil? || e[1].empty? } .to_h all_errors[:entries] = entry_error_collection unless entry_error_collection.empty? all_errors unless all_errors.empty? end |
#to_s ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/aba/batch.rb', line 53 def to_s raise RuntimeError, 'No entries present - add one using `add_transaction` or `add_return`' if entries.empty? raise RuntimeError, 'ABA data is invalid - check the contents of `errors`' unless valid? # Descriptive record output = "#{descriptive_record}\r\n" # Transactions records output += entries.map { |t| t.to_s }.join("\r\n") # Batch control record output += "\r\n#{batch_control_record}" end |
#transactions ⇒ Object
75 76 77 |
# File 'lib/aba/batch.rb', line 75 def transactions entries.select { |entry| entry.instance_of?(Aba::Transaction) } end |
#transactions_valid? ⇒ Boolean
79 80 81 |
# File 'lib/aba/batch.rb', line 79 def transactions_valid? !transactions.map { |t| t.valid? }.include?(false) end |
#valid? ⇒ Boolean
83 84 85 |
# File 'lib/aba/batch.rb', line 83 def valid? !has_errors? && !has_entry_errors? end |