Class: Aba::Batch
Constant Summary
Constants included from Validations
Validations::BECS_PATTERN, Validations::INDICATORS
Instance Attribute Summary collapse
-
#bsb ⇒ Object
Returns the value of attribute bsb.
-
#description ⇒ Object
Returns the value of attribute description.
-
#financial_institution ⇒ Object
Returns the value of attribute financial_institution.
-
#process_at ⇒ Object
Returns the value of attribute process_at.
-
#transactions ⇒ Object
Returns the value of attribute transactions.
-
#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_transaction(attrs = {}) ⇒ Object
- #errors ⇒ Object
-
#initialize(attrs = {}, transactions = []) {|_self| ... } ⇒ Batch
constructor
A new instance of Batch.
- #to_s ⇒ Object
- #transactions_valid? ⇒ Boolean
- #valid? ⇒ Boolean
Methods included from Validations
Constructor Details
#initialize(attrs = {}, transactions = []) {|_self| ... } ⇒ Batch
Returns a new instance of Batch.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aba/batch.rb', line 32 def initialize(attrs = {}, transactions = []) attrs.each do |key, value| send("#{key}=", value) end @transaction_index = 0 @transactions = {} 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.
5 6 7 |
# File 'lib/aba/batch.rb', line 5 def bsb @bsb end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/aba/batch.rb', line 5 def description @description end |
#financial_institution ⇒ Object
Returns the value of attribute financial_institution.
5 6 7 |
# File 'lib/aba/batch.rb', line 5 def financial_institution @financial_institution end |
#process_at ⇒ Object
Returns the value of attribute process_at.
5 6 7 |
# File 'lib/aba/batch.rb', line 5 def process_at @process_at end |
#transactions ⇒ Object
Returns the value of attribute transactions.
5 6 7 |
# File 'lib/aba/batch.rb', line 5 def transactions @transactions end |
#user_id ⇒ Object
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/aba/batch.rb', line 5 def user_id @user_id end |
#user_name ⇒ Object
Returns the value of attribute user_name.
5 6 7 |
# File 'lib/aba/batch.rb', line 5 def user_name @user_name end |
Instance Method Details
#add_transaction(attrs = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/aba/batch.rb', line 63 def add_transaction(attrs = {}) if attrs.instance_of?(Aba::Transaction) transaction = attrs else transaction = Aba::Transaction.new(attrs) end @transactions[@transaction_index] = transaction @transaction_index += 1 transaction end |
#errors ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/aba/batch.rb', line 82 def errors # Run validations has_errors? has_transaction_errors? # Build errors all_errors = {} all_errors[:aba] = self.error_collection unless self.error_collection.empty? transaction_error_collection = @transactions.each_with_index.map{ |(k, t), i| [k, t.error_collection] }.reject{ |e| e[1].nil? || e[1].empty? }.to_h all_errors[:transactions] = transaction_error_collection unless transaction_error_collection.empty? all_errors unless all_errors.empty? end |
#to_s ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/aba/batch.rb', line 49 def to_s raise RuntimeError, 'No transactions present - add one using `add_transaction`' if @transactions.empty? raise RuntimeError, 'ABA data is invalid - check the contents of `errors`' unless valid? # Descriptive record output = "#{descriptive_record}\r\n" # Transactions records output += @transactions.map{ |t| t[1].to_s }.join("\r\n") # Batch control record output += "\r\n#{batch_control_record}" end |
#transactions_valid? ⇒ Boolean
74 75 76 |
# File 'lib/aba/batch.rb', line 74 def transactions_valid? !has_transaction_errors? end |
#valid? ⇒ Boolean
78 79 80 |
# File 'lib/aba/batch.rb', line 78 def valid? !has_errors? && transactions_valid? end |