Module: Taxedo::Builder::Price

Defined in:
lib/taxedo/builder/price.rb

Class Method Summary collapse

Class Method Details

.currency_symbol(unit) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/taxedo/builder/price.rb', line 4

def self.currency_symbol(unit)
  return case unit.downcase
    when 'cad', 'usd' then '$'
    when 'eur' then ''
    when 'chf' then 'CHF'
    else ''
  end
end

.price(amount, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/taxedo/builder/price.rb', line 13

def self.price(amount, options={})
  options = { separator: ',', format: '%n%u', unit: 'cad' }.merge(options)

  result = amount.to_s.rjust(3,'0')
  result = result[0..-3] + options[:separator] + result[-2..-1]
  result = options[:format].gsub('%u', currency_symbol(options[:unit])).gsub('%n', result) if options[:unit]

  return result
end