Class: Headache::Batch
- Inherits:
-
Object
- Object
- Headache::Batch
- Includes:
- Enumerable
- Defined in:
- lib/headache/batch.rb
Instance Attribute Summary collapse
-
#batch_number ⇒ Object
Returns the value of attribute batch_number.
-
#company_identification ⇒ Object
Returns the value of attribute company_identification.
-
#company_name ⇒ Object
Returns the value of attribute company_name.
-
#descriptive_date ⇒ Object
Returns the value of attribute descriptive_date.
-
#discretionary ⇒ Object
Returns the value of attribute discretionary.
-
#document ⇒ Object
Returns the value of attribute document.
-
#effective_date ⇒ Object
Returns the value of attribute effective_date.
-
#entry_class_code ⇒ Object
Returns the value of attribute entry_class_code.
-
#entry_description ⇒ Object
Returns the value of attribute entry_description.
-
#entry_hash ⇒ Object
Returns the value of attribute entry_hash.
-
#odfi_id ⇒ Object
Returns the value of attribute odfi_id.
-
#service_code ⇒ Object
Returns the value of attribute service_code.
-
#total_credit ⇒ Object
Returns the value of attribute total_credit.
-
#total_debit ⇒ Object
Returns the value of attribute total_debit.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(entry_or_entries) ⇒ Object
- #add_entry(entry) ⇒ Object
- #control ⇒ Object
- #entries ⇒ Object
- #header ⇒ Object
-
#initialize(document = nil) ⇒ Batch
constructor
A new instance of Batch.
- #method_missing(m, *args, &block) ⇒ Object
- #parse(records) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(document = nil) ⇒ Batch
Returns a new instance of Batch.
26 27 28 29 |
# File 'lib/headache/batch.rb', line 26 def initialize(document = nil) @document = document @members = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
79 80 81 |
# File 'lib/headache/batch.rb', line 79 def method_missing(m, *args, &block) entries.send m, *args, &block end |
Instance Attribute Details
#batch_number ⇒ Object
Returns the value of attribute batch_number.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def batch_number @batch_number end |
#company_identification ⇒ Object
Returns the value of attribute company_identification.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def company_identification @company_identification end |
#company_name ⇒ Object
Returns the value of attribute company_name.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def company_name @company_name end |
#descriptive_date ⇒ Object
Returns the value of attribute descriptive_date.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def descriptive_date @descriptive_date end |
#discretionary ⇒ Object
Returns the value of attribute discretionary.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def discretionary @discretionary end |
#document ⇒ Object
Returns the value of attribute document.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def document @document end |
#effective_date ⇒ Object
Returns the value of attribute effective_date.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def effective_date @effective_date end |
#entry_class_code ⇒ Object
Returns the value of attribute entry_class_code.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def entry_class_code @entry_class_code end |
#entry_description ⇒ Object
Returns the value of attribute entry_description.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def entry_description @entry_description end |
#entry_hash ⇒ Object
Returns the value of attribute entry_hash.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def entry_hash @entry_hash end |
#odfi_id ⇒ Object
Returns the value of attribute odfi_id.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def odfi_id @odfi_id end |
#service_code ⇒ Object
Returns the value of attribute service_code.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def service_code @service_code end |
#total_credit ⇒ Object
Returns the value of attribute total_credit.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def total_credit @total_credit end |
#total_debit ⇒ Object
Returns the value of attribute total_debit.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def total_debit @total_debit end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/headache/batch.rb', line 5 def type @type end |
Class Method Details
.type_from_service_code(code) ⇒ Object
31 32 33 34 35 |
# File 'lib/headache/batch.rb', line 31 def self.type_from_service_code(code) return :credit if code.to_s == '220' return :debit if code.to_s == '225' fail Headache::UnknownServiceCode, "unknown service code: #{code.inspect} (expecting 220 or 225)" end |
Instance Method Details
#<<(entry_or_entries) ⇒ Object
74 75 76 77 |
# File 'lib/headache/batch.rb', line 74 def <<(entry_or_entries) [(entries.is_a?(Array) ? entry_or_entries : [entry_or_entries])].flatten.each { |e| add_entry e } self end |
#add_entry(entry) ⇒ Object
69 70 71 72 |
# File 'lib/headache/batch.rb', line 69 def add_entry(entry) entry.batch = self @members << entry end |
#control ⇒ Object
47 48 49 |
# File 'lib/headache/batch.rb', line 47 def control @control ||= Record::BatchControl.new self, @documentec end |
#entries ⇒ Object
51 52 53 |
# File 'lib/headache/batch.rb', line 51 def entries @members end |
#header ⇒ Object
43 44 45 |
# File 'lib/headache/batch.rb', line 43 def header @header ||= Record::BatchHeader.new self, @document end |
#parse(records) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/headache/batch.rb', line 11 def parse(records) @header = Record::BatchHeader.new(self, @document).parse(records.shift) @control = Record::BatchControl.new(self, @document).parse(records.pop) records.each { |r| @members << Headache::Record::Entry.new(self, @document).parse(r) } self end |
#to_h ⇒ Object
59 60 61 62 63 |
# File 'lib/headache/batch.rb', line 59 def to_h { batch_header: @header.to_h, entries: @members.to_a.map(&:to_h), batch_control: @control.to_h } end |