class Headache::Batch

Attributes

batch_number[RW]
company_identification[RW]
company_name[RW]
descriptive_date[RW]
discretionary[RW]
document[RW]
effective_date[RW]
entry_class_code[RW]
entry_description[RW]
entry_hash[RW]
odfi_id[RW]
service_code[RW]
total_credit[RW]
total_debit[RW]
type[RW]

Public Class Methods

new(document = nil) click to toggle source
# File lib/headache/batch.rb, line 26
def initialize(document = nil)
  @document = document
  @members  = []
end
type_from_service_code(code) click to toggle source
# 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

Public Instance Methods

<<(entry_or_entries) click to toggle source
# 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) click to toggle source
# File lib/headache/batch.rb, line 69
def add_entry(entry)
  entry.batch = self
  @members << entry
end
control() click to toggle source
# File lib/headache/batch.rb, line 47
def control
  @control ||= Record::BatchControl.new self, @documentec
end
entries() click to toggle source
# File lib/headache/batch.rb, line 51
def entries
  @members
end
header() click to toggle source
# File lib/headache/batch.rb, line 43
def header
  @header ||= Record::BatchHeader.new self, @document
end
method_missing(m, *args, &block) click to toggle source
# File lib/headache/batch.rb, line 79
def method_missing(m, *args, &block)
  entries.send m, *args, &block
end
parse(records) click to toggle source
# 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() click to toggle source
# 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