Module: TwitterCldr::Shared::Currencies

Defined in:
lib/twitter_cldr/shared/currencies.rb

Class Method Summary collapse

Class Method Details

.currency_codes(locale = :en) ⇒ Object



10
11
12
# File 'lib/twitter_cldr/shared/currencies.rb', line 10

def currency_codes(locale = :en)
  resource(locale).keys.map { |c| c.to_s }
end

.for_code(currency_code, locale = :en) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/twitter_cldr/shared/currencies.rb', line 14

def for_code(currency_code, locale = :en)
  currency_code = currency_code.to_sym
  data = resource(locale)[currency_code]
  symbol_data = iso_currency_symbols[currency_code]

  if data
    result = {
      currency:    currency_code,
      name:        data[:name],
      cldr_symbol: data[:symbol] || currency_code.to_s,
      symbol:      data[:symbol] || currency_code.to_s,
      code_points: (data[:symbol] || currency_code.to_s).unpack("U*")
    }

    result.merge!(symbol_data) if symbol_data
  end

  result
end