Class: Maguire::Currency

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/maguire/currency.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(iso_data = {}) ⇒ Currency

Returns a new instance of Currency.



6
7
8
9
# File 'lib/maguire/currency.rb', line 6

def initialize(iso_data={})
  @data = iso_data
  super
end

Class Method Details

.coded(code) ⇒ Object



35
36
37
# File 'lib/maguire/currency.rb', line 35

def coded(code)
  self.new(Maguire.data_paths.load(code.downcase))
end

Instance Method Details

#as_jsonObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/maguire/currency.rb', line 23

def as_json
  {
    name: name,
    code: code,
    minor_units: minor_units,
    precision: precision,
    symbol: symbol,
    symbol_html: symbol_html
  }
end

#inspectObject



15
16
17
# File 'lib/maguire/currency.rb', line 15

def inspect
  "<##{self.class} name=#{name} code=#{code}>"
end

#overlay(locale_data = {}) ⇒ Object



19
20
21
# File 'lib/maguire/currency.rb', line 19

def overlay(locale_data={})
  Currency.new(Maguire::Hash.merge([@data, locale_data]))
end

#precisionObject



11
12
13
# File 'lib/maguire/currency.rb', line 11

def precision
  minor_unit_to_major_unit || 10 ** minor_units
end