Module: Worldwide::Currencies

Extended by:
Currencies
Includes:
Enumerable
Included in:
Currencies
Defined in:
lib/worldwide/currencies.rb

Constant Summary collapse

CURRENCIES_FILE_PATH =
File.join(Worldwide::Paths::CLDR_ROOT, "locales", "en", "currencies.yml")
CURRENCY_CODES_FILE_PATH =
File.join(Worldwide::Paths::OTHER_DATA_ROOT, "currency", "codes.yml")

Instance Method Summary collapse

Instance Method Details

#allObject



14
15
16
# File 'lib/worldwide/currencies.rb', line 14

def all
  all_currencies
end

#alpha_code_for(numeric_code) ⇒ Object

Convert ISO-4217 numeric-three code to ISO-4217 alpha-three code Returns nil if there is no such numeric code.



20
21
22
23
24
25
26
27
# File 'lib/worldwide/currencies.rb', line 20

def alpha_code_for(numeric_code)
  lookup_code = if numeric_code.is_a?(Integer)
    numeric_code
  else
    numeric_code&.to_s&.to_i
  end
  numeric_three_to_alpha_three_db[lookup_code]&.to_s
end

#each(&block) ⇒ Object



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

def each(&block)
  all_currencies.each(&block)
end

#numeric_code_for(alpha_code) ⇒ Object

Convert ISO-4217 alpha-three code to ISO-4217 numeric-three code Note that we support some currencies (e.g. JEP) that are not recognized by ISO, and there is no numeric-three code for these currencies, so nil will be returned.



32
33
34
# File 'lib/worldwide/currencies.rb', line 32

def numeric_code_for(alpha_code)
  currency_codes.dig(alpha_code&.to_s&.upcase, "three_digit_code")&.to_i
end