Class: Farmoney::Vat
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Farmoney::Vat
- Defined in:
- lib/farmoney/vat.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_decimal ⇒ Object
-
#initialize(rate, precision: 2) ⇒ Vat
constructor
A new instance of Vat.
- #multiplier ⇒ Object
- #per_thousand ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(rate, precision: 2) ⇒ Vat
Returns a new instance of Vat.
13 14 15 16 |
# File 'lib/farmoney/vat.rb', line 13 def initialize(rate, precision: 2) @rate = BigDecimal.new(rate, precision) super(@rate) end |
Class Method Details
.from_decimal(rate) ⇒ Object
5 6 7 |
# File 'lib/farmoney/vat.rb', line 5 def self.from_decimal(rate) new(100 * rate) end |
.from_thousandth(rate) ⇒ Object
9 10 11 |
# File 'lib/farmoney/vat.rb', line 9 def self.from_thousandth(rate) new(BigDecimal(rate) / 10) end |
Instance Method Details
#as_decimal ⇒ Object
26 27 28 |
# File 'lib/farmoney/vat.rb', line 26 def as_decimal @rate / 100 end |
#multiplier ⇒ Object
22 23 24 |
# File 'lib/farmoney/vat.rb', line 22 def multiplier 1 + as_decimal end |
#per_thousand ⇒ Object
30 31 32 |
# File 'lib/farmoney/vat.rb', line 30 def per_thousand (10 * @rate).to_i end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/farmoney/vat.rb', line 18 def to_s "#{@rate}%" end |