class Vatcalc::Bill::GNVCollection

A GNVCollection consists basically of a an 2D Array of GNV GNV Objects +@see Vatcalc::GNV+ It's a helper class to calculate amounts and iterate through specific GNV objects.

Attributes

collection[R]
currency[RW]

Public Class Methods

for() click to toggle source

which class can be inserted in the collection

# File lib/vatcalc/bill.rb, line 91
def self.for
  GNV
end
new(col=[],currency = nil) click to toggle source
# File lib/vatcalc/bill.rb, line 95
def initialize(col=[],currency = nil)
  @collection = col
  @currency = currency
end

Public Instance Methods

+(other) click to toggle source
# File lib/vatcalc/bill.rb, line 121
def +(other)
  raise(TypeError.new) unless other.is_a?(GNVCollection)
  GNVCollection.new(@collection + other.collection,@currency)
end
<<(arg) click to toggle source
# File lib/vatcalc/bill.rb, line 109
def <<(arg)
  insert(arg,1) 
end
each() { |*arr| ... } click to toggle source
# File lib/vatcalc/bill.rb, line 126
def each
  result = []
  @collection.each do |gnv,quantity|
    arr = [gnv.source, quantity, gross*quantity, net*quantity, vat*quantity]
    result << arr
    yield *arr
  end
  result 
end
each_gnv() { |gnv, quantity| ... } click to toggle source
# File lib/vatcalc/bill.rb, line 136
def each_gnv
  @collection.each {|gnv,quantity| yield gnv, quantity }
end
insert(gnv,quantity) click to toggle source
# File lib/vatcalc/bill.rb, line 100
def insert(gnv,quantity)
  raise(TypeError.new) unless gnv.is_a?(self.class.for)
  @currency = gnv.currency
  @vat_splitted = nil
  @collection << [gnv,quantity]
  @gross, @vat, @net = [nil] * 3
  self
end
vat_splitted() click to toggle source
# File lib/vatcalc/bill.rb, line 113
def vat_splitted
  @vat_splitted ||= @collection.inject(GNV.new(0,0,@currency)){|sum,(gnv,q)| sum += (gnv * q) }.vat_splitted
end

Private Instance Methods

money_hash() click to toggle source
# File lib/vatcalc/bill.rb, line 142
def money_hash
  Hash.new(new_money)
end
new_money() click to toggle source
# File lib/vatcalc/bill.rb, line 146
def new_money
  Money.new(0,@currency)
end