Class: Vatcalc::BaseElement
- Includes:
- Comparable
- Defined in:
- lib/vatcalc/base_element.rb
Instance Attribute Summary collapse
-
#vat_percentage ⇒ Object
(also: #percentage, #vat_p)
readonly
Returns the value of attribute vat_percentage.
Attributes inherited from GNV
Instance Method Summary collapse
- #==(oth) ⇒ Object
- #hash ⇒ Object
-
#initialize(amount, currency: nil, vat_percentage: nil, net: false) ⇒ BaseElement
constructor
Initalizes a new Object of an BaseElement Assumes that the amount is a gross value but you can pass a net value as well if you pass the option net: true .
- #inspect ⇒ Object
Methods inherited from GNV
#*, #-@, #<=>, #coerce, #gross, #net, #to_gnv, #vat, #vat_splitted
Constructor Details
#initialize(amount, currency: nil, vat_percentage: nil, net: false) ⇒ BaseElement
Initalizes a new Object of an BaseElement Assumes that the amount is a gross value but you can pass a net value as well if you pass the option net: true
> b = BaseElement.new 10.00, vat_percentage: 19, currency: “EUR”
b.net.to_f = 8.40
> b = BaseElement.new 10.00, vat_percentage: 7, currency: “USD”
b.net.to_f = 9.35
> b = BaseElement.new 10.00, vat_percentage: 7, currency: “USD”, net: true
> b.gross = 10.70
32 33 34 35 36 37 38 39 |
# File 'lib/vatcalc/base_element.rb', line 32 def initialize(amount,currency: nil, vat_percentage: nil, net: false) @currency = currency || Vatcalc.currency amount = Util.to_money(amount,@currency) vp = Util.to_vat_percentage(vat_percentage) @vector = net ? Vector[amount * vp, amount] : Vector[amount, amount / vp] @vat_percentage = vp @vat_splitted = {@vat_percentage => vat} end |
Instance Attribute Details
#vat_percentage ⇒ Object (readonly) Also known as: percentage, vat_p
Returns the value of attribute vat_percentage.
12 13 14 |
# File 'lib/vatcalc/base_element.rb', line 12 def vat_percentage @vat_percentage end |
Instance Method Details
#==(oth) ⇒ Object
46 47 48 |
# File 'lib/vatcalc/base_element.rb', line 46 def ==(oth) oth.is_a?(BaseElement) && (oth.vector == @vector) && (vat_p == oth.vat_p) end |
#hash ⇒ Object
41 42 43 44 |
# File 'lib/vatcalc/base_element.rb', line 41 def hash #vector comes from GNV [@vector,@vat_percentage].hash end |
#inspect ⇒ Object
51 52 53 |
# File 'lib/vatcalc/base_element.rb', line 51 def inspect "#<#{self.class.name} vat_percentage:#{vat_p} gross:#{gross} net: #{net} vat:#{vat} currency:#{@currency}>" end |