class Vatcalc::GNV
Attributes
currency[R]
source[RW]
vector[R]
Public Class Methods
new(gross,net,cur=nil)
click to toggle source
# File lib/vatcalc/gnv.rb, line 22 def initialize(gross,net,cur=nil) @currency ||= (cur || Vatcalc.currency) init_vector(gross,net) end
Public Instance Methods
*(oth)
click to toggle source
# File lib/vatcalc/gnv.rb, line 36 def *(oth) gnv = oth.is_a?(Numeric) ? to_gnv(@vector * oth) : raise(TypeError.new) gnv.tap do |g| h = new_money_hash self.vat_splitted.each {|vp,m| h[vp] = m*oth} g.vat_splitted = h end end
-@()
click to toggle source
For usage of => - GNV.new
(100.00,90.00)
# File lib/vatcalc/gnv.rb, line 46 def -@ to_gnv(-@vector) end
<=>(other)
click to toggle source
# File lib/vatcalc/gnv.rb, line 57 def <=>(other) if other.respond_to?(:net) net <=> other.net else net <=> other end end
==(oth)
click to toggle source
# File lib/vatcalc/gnv.rb, line 51 def ==(oth) oth.is_a?(GNV) && oth.vector == @vector end
Also aliased as: eql?
coerce(oth)
click to toggle source
@see www.mutuallyhuman.com/blog/2011/01/25/class-coercion-in-ruby
# File lib/vatcalc/gnv.rb, line 68 def coerce(oth) [self,oth] end
gross()
click to toggle source
# File lib/vatcalc/gnv.rb, line 72 def gross @vector[0] end
hash()
click to toggle source
Returns a Integer hash value based on the value
in order to use functions like & (intersection), group_by, etc.
@return [Integer]
@example
GNV.new(19,11).hash #=> 908351
# File lib/vatcalc/gnv.rb, line 91 def hash @vector.hash end
net()
click to toggle source
# File lib/vatcalc/gnv.rb, line 76 def net @vector[1] end
to_gnv(v=@vector)
click to toggle source
# File lib/vatcalc/gnv.rb, line 100 def to_gnv(v=@vector) GNV.new(v[0],v[1],@currency) end
vat()
click to toggle source
Always gross - net
# File lib/vatcalc/gnv.rb, line 96 def vat gross - net end
vat_splitted()
click to toggle source
# File lib/vatcalc/gnv.rb, line 80 def vat_splitted @vat_splitted ||= new_money_hash end
Protected Instance Methods
vat_splitted=(h)
click to toggle source
# File lib/vatcalc/gnv.rb, line 106 def vat_splitted=(h) @vat_splitted = h end
Private Instance Methods
init_vector(g,n)
click to toggle source
# File lib/vatcalc/gnv.rb, line 112 def init_vector(g,n) @vector = Vector[*[g,n].map{|i| Util.to_money(i,@currency)}] end
new_money_hash()
click to toggle source
# File lib/vatcalc/gnv.rb, line 116 def new_money_hash Hash.new(Money.new(0,@currency)) end