Class: Headache::Batch

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/headache/batch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_numberObject

Returns the value of attribute batch_number.



5
6
7
# File 'lib/headache/batch.rb', line 5

def batch_number
  @batch_number
end

#company_identificationObject

Returns the value of attribute company_identification.



5
6
7
# File 'lib/headache/batch.rb', line 5

def company_identification
  @company_identification
end

#company_nameObject

Returns the value of attribute company_name.



5
6
7
# File 'lib/headache/batch.rb', line 5

def company_name
  @company_name
end

#descriptive_dateObject

Returns the value of attribute descriptive_date.



5
6
7
# File 'lib/headache/batch.rb', line 5

def descriptive_date
  @descriptive_date
end

#discretionaryObject

Returns the value of attribute discretionary.



5
6
7
# File 'lib/headache/batch.rb', line 5

def discretionary
  @discretionary
end

#documentObject

Returns the value of attribute document.



5
6
7
# File 'lib/headache/batch.rb', line 5

def document
  @document
end

#effective_dateObject

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_codeObject

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_descriptionObject

Returns the value of attribute entry_description.



5
6
7
# File 'lib/headache/batch.rb', line 5

def entry_description
  @entry_description
end

#entry_hashObject

Returns the value of attribute entry_hash.



5
6
7
# File 'lib/headache/batch.rb', line 5

def entry_hash
  @entry_hash
end

#odfi_idObject

Returns the value of attribute odfi_id.



5
6
7
# File 'lib/headache/batch.rb', line 5

def odfi_id
  @odfi_id
end

#service_codeObject

Returns the value of attribute service_code.



5
6
7
# File 'lib/headache/batch.rb', line 5

def service_code
  @service_code
end

#total_creditObject

Returns the value of attribute total_credit.



5
6
7
# File 'lib/headache/batch.rb', line 5

def total_credit
  @total_credit
end

#total_debitObject

Returns the value of attribute total_debit.



5
6
7
# File 'lib/headache/batch.rb', line 5

def total_debit
  @total_debit
end

#typeObject

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

#controlObject



47
48
49
# File 'lib/headache/batch.rb', line 47

def control
  @control ||= Record::BatchControl.new self, @documentec
end

#entriesObject



51
52
53
# File 'lib/headache/batch.rb', line 51

def entries
  @members
end

#headerObject



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_hObject



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