Module: Worldwide::Currencies

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

Instance Method Summary collapse

Instance Method Details

#allObject



23
24
25
# File 'lib/worldwide/currencies.rb', line 23

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.



29
30
31
32
33
34
35
36
# File 'lib/worldwide/currencies.rb', line 29

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



19
20
21
# File 'lib/worldwide/currencies.rb', line 19

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.



41
42
43
# File 'lib/worldwide/currencies.rb', line 41

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