class Vatcalc::Util
Public Class Methods
convert_to_money(obj,curr=nil)
click to toggle source
Converts an Object into a Money object @return [Money] @example
=> Vatcalc::Util.convert_to_money(10.00)
# File lib/vatcalc/util.rb, line 13 def convert_to_money(obj,curr=nil) curr ||= Vatcalc.currency case obj when Money obj when Integer Money.new(obj,curr) when Numeric Money.new(obj*100,curr) else raise InvalidAmountError.new "Can't convert #{obj.class} to an Money instance" end end
convert_to_vat_percentage(vat_percentage)
click to toggle source
Converts an Object into an VATPercentage
Object @return [VATPercentage]
@example
=> Vatcalc::Util.to_vat_percentage
# File lib/vatcalc/util.rb, line 37 def convert_to_vat_percentage(vat_percentage) case vat_percentage when VATPercentage vat_percentage when nil Vatcalc.vat_percentage else VATPercentage.new(vat_percentage) end end
Also aliased as: to_vat_percentage, to_vat_p
human_percentage_value(value,precision=2)
click to toggle source
Returns a human friendly percentage value @param value = [Float,Integer,String]
=> human_percentage_value(0.19) => 19%
# File lib/vatcalc/util.rb, line 55 def human_percentage_value(value,precision=2) full, fraction = ((value.to_f)*100).to_f.round(precision).divmod(1) full.to_s + (fraction > 0.00 ? ("," + fraction.round(precision).to_s[2..-1]) : "") + "%" end
to_vat_percentage(vat_percentage)
ALIAS for convert_to_vat_percentage
method
Alias for: convert_to_vat_percentage