lib/ach/batch.rb in ach_builder-0.0.2 vs lib/ach/batch.rb in ach_builder-0.2.1
- old
+ new
@@ -1,37 +1,15 @@
module ACH
+ # Represents an ACH::Component, which is located under ACH::File and
+ # contains a variable number of ACH::Record::Entry and ACH::Record::Addenda
+ # records itself.
class Batch < Component
+ autoload :Builder
+ autoload :Control
+ autoload :Header
+
+ include Builder
+
has_many :entries
-
- def has_credit?
- entries.any?(&:credit?)
- end
-
- def has_debit?
- entries.any?(&:debit?)
- end
-
- def entry_count
- entries.length
- end
-
- def entry_hash
- entries.map{ |e| e.routing_number.to_i / 10 }.compact.inject(&:+)
- end
-
- def total_debit_amount
- entries.select(&:debit?).map{ |e| e.amount.to_i }.compact.inject(&:+) || 0
- end
-
- def total_credit_amount
- entries.select(&:credit?).map{ |e| e.amount.to_i }.compact.inject(&:+) || 0
- end
-
- def to_ach
- [header] + entries + [control]
- end
-
- def before_header
- attributes[:service_class_code] ||= (has_debit? && has_credit? ? 200 : has_debit? ? 225 : 220)
- end
+ has_many :addendas, :linked_to => :entries
end
end