Module: ISO4217

Defined in:
lib/iso4217/iso4217.rb,
lib/iso4217/currency.rb,
lib/iso4217/currencies.rb

Defined Under Namespace

Classes: Currency

Constant Summary collapse

COUNTRIES =
{
  :BE => EURO, 
  :BG => EURO,
  :CA => CANADIAN_DOLLAR,
  :CZ => EURO,
  :DK => EURO,
  :DE => EURO,
  :EE => EURO,
  :IE => EURO,
  :EL => EURO,
  :ES => EURO,
  :FR => EURO,
  :GB => BRITAIN_POUND, 
  :IT => EURO,
  :CY => EURO,
  :LV => EURO,
  :LT => EURO,
  :LU => EURO,
  :HU => EURO,
  :MT => EURO,
  :NL => EURO,
  :AT => EURO,
  :PL => EURO,
  :PT => EURO,
  :RO => EURO,
  :SI => EURO,
  :SK => EURO,
  :FI => EURO,
  :SE => EURO,
  :UK => BRITAIN_POUND,
  :US => AMERICAN_DOLLAR 
}
GENERIC_CURRENCY_SIGN =
"U+00a4"
DOLLAR_SIGN =
"U+0024"
POUND_SIGN =
"U+00a3"
CURRENCIES =
[
  ALBANIAN_LEKE=                  Currency.new(:ALL, "U+004cU+0065U+6b", 'Lek'),
  AMERICAN_DOLLAR=                Currency.new(:USD, DOLLAR_SIGN, 'US dollar'),
  AFGHANI=                        Currency.new(:AFN, "U+060b", 'Afghani'),
  ARGENTINA_PESOS=                Currency.new(:ARS, "U+0024", 'Argentine peso'),
  ARUBAN_GUILDER=                 Currency.new(:AWG, "U+0192", 'Aruban guilder'),
  AUSTRALIAN_DOLLAR=              Currency.new(:AUD, DOLLAR_SIGN, 'Australian dollar'),
  AZERBAIJANIAN_MANAT=            Currency.new(:AZN, "U+043cU+0430U+043d", 'Azerbaijanian manat'),
  BAHAMAS_DOLLAR=                 Currency.new(:BSD, DOLLAR_SIGN, 'Bahamian dollar'),
  BARBADOS_DOLLAR=                Currency.new(:BBD, DOLLAR_SIGN, 'Barbados dollar'),
  BELARUS_RUBLE=                  Currency.new(:BYR, "U+0070U+002e", 'Belarusian ruble'),
  BELIZE_DOLLAR=                  Currency.new(:BZD, "U+0042U+005aU+0024", 'Belize dollar'),
  BERMUDA_DOLLARS=                Currency.new(:BMD, DOLLAR_SIGN, 'Bermudian dollar'),
  BOLIVIA_BOLIVIANOS=             Currency.new(:BOB, "#{DOLLAR_SIGN}U+0062", 'Boliviano'),
  CONVERTIBLE_MARKA=              Currency.new(:BAM, "U+004bU+004d", 'Convertible marka'), 
  BOTSWANA_PULAS=                 Currency.new(:BWP, "U+0050", 'Pula'),
  BULGARIAN_LEVA=                 Currency.new(:BGN, "U+043bU+0432", 'Bulgarian lev'),
  BRAZILIAN_REAL=                 Currency.new(:BRL, "U+0052#{DOLLAR_SIGN}", 'Brazilian real'),
  BRITAIN_POUND=                  Currency.new(:GBP, "U+00a3", 'Pound sterling'),
  BRUNEI_DARUSSALAM_DOLLAR=       Currency.new(:BND, DOLLAR_SIGN, 'Brunei dollar'),
  CAMBODIAN_RIELS=                Currency.new(:KHR, "U+17db", 'Riel'),
  CANADIAN_DOLLAR=                Currency.new(:CAD, "CanU+0024", 'Canadian dollar'),
  CAYMAN_ISLANDS_DOLLARS=         Currency.new(:KYD, DOLLAR_SIGN, 'Cayman Islands dollar'),
  CHILE_PESOS=                    Currency.new(:CLP, DOLLAR_SIGN, 'Chilean peso'),
  CHINA_YUAN_RENMINBI=            Currency.new(:CNY, "U+00a5", 'Chinese Yuan'),
  COLOMBIAN_PESO=                 Currency.new(:COP, DOLLAR_SIGN, 'Colombian peso'),
  COSTA_RICA_COLON=               Currency.new(:CRC, "U+20a1", 'Costa Rica colon'),
  CROATIAN_KUNA=                  Currency.new(:HRK, "U+006bU+006e", 'Croatian kuna'),
  CUBA_PESOS=                     Currency.new(:CUP, "U+20b1", 'Cuban peso'),
  CZECH_KORUNA=                   Currency.new(:CZK, "U+004bU+010d", 'Czech Koruna'),
  DENMARK_KRONER=                 Currency.new(:DKK, "U+006bU+0072", 'Danish krone'),
  DOMINICAN_REPUBLIC_PESOS=       Currency.new(:DOP, "U+0052U+0044U+0024", 'Dominican peso'),
  EAST_CARIBBEAN_DOLLAR=          Currency.new(:XCD, DOLLAR_SIGN, 'East Caribbean dollar'),
  EGYPT_POUND=                    Currency.new(:EGP, POUND_SIGN, 'Egyptian pound'),
  EL_SALVADOR_COLON=              Currency.new(:SVC, DOLLAR_SIGN, 'Salvadoran colón'),
  ESTONIAN_KROONI=                Currency.new(:EEK, "U+006bU+0072", 'Kroon'),
  EURO=                           Currency.new(:EUR, "U+20ac", 'euro'),
  FALKLAND_ISLANDS_POUND=         Currency.new(:FKP, POUND_SIGN, 'Falkland Islands pound'),
  FIJI_DOLLAR=                    Currency.new(:FJD, DOLLAR_SIGN, 'Fiji dollar'),
  GHANA_CEDI=                     Currency.new(:GHC, "U+00a2", 'Ghanian cedi'),
  GIBRLATAR_POUND=                Currency.new(:GIP, POUND_SIGN, 'Gibraltar pound'),
  GUATEMALA_QUEZALES=             Currency.new(:GTQ, "U+0051", 'Quezal'),
  GUERNSEY_POUND=                 Currency.new(:GGP, POUND_SIGN, 'Guernsey pound'),
  GUYANA_DOLLAR=                  Currency.new(:GYD, DOLLAR_SIGN, 'Guyana dollar'),
  HONDURAS_LEMPIRAS=              Currency.new(:HNL, "U+004c", 'Lempira'),
  HONG_KONG_DOLLAR=               Currency.new(:HKD, DOLLAR_SIGN, 'Hong Kong dollar'),
  HUNGARY_FLORINT=                Currency.new(:HUF, "U+0046U+0074", 'Floringt'),
  ICELAND_KRONUR=                 Currency.new(:ISK, "U+006bU+0072", 'Iceland krona'),
  INDIAN_RUPEE=                   Currency.new(:INR, "U+20a8", 'Indian rupee'),
  INDONESIAN_RUPIAH=              Currency.new(:IDR, "U+0082U+0112", 'Rupiah'),
  IRAN_RIALS=                     Currency.new(:IRR, "U+fdfc", 'Iranian rial'),
  ISLE_OF_MAN_POUND=              Currency.new(:IMP, POUND_SIGN, 'Pound'),
  ISRAEL_NEW_SHEKEL=              Currency.new(:ILS, "U+20aa", 'Israeli new sheqel'),
  JAMAICA_DOLLAR=                 Currency.new(:JMD, "U+004a#{DOLLAR_SIGN}", 'Jamaican dollar'),
  JAPAN_YEN=                      Currency.new(:JPY, "U+00a5", 'Japanese yen'),
  JERSEY_POUND=                   Currency.new(:JEP, POUND_SIGN, 'Jersey pound'),
  KAZAKHSTAN_TENGE=               Currency.new(:KZT, "U+043bU+432", 'Tenge'),
  NORTH_KOREAN_WON=               Currency.new(:KPW, "U+20a9", 'North Korean won'),
  SOUTH_KOREAN_WON=               Currency.new(:KRW, "U+20a9", 'South Korean won'),
  KYRGYZSTAN_SOMS=                Currency.new(:KGS, "U+043bU+0432", 'Som'),
  LAOS_KIPS=                      Currency.new(:LAK, "U+20ad", 'Kip'),
  LATVIAN_LATI=                   Currency.new(:LVL, "U+004cU+0073", 'Latvian lats'),
  LEBANON_POUND=                  Currency.new(:LBP, POUND_SIGN, 'Lebanese pound'),
  LIBERIA_DOLLARS=                Currency.new(:LRD, DOLLAR_SIGN, 'Liberian dollar'),
  SWITZERLAND_FRANCS=             Currency.new(:CHF, "U+0043U+0048U+0046", 'Swiss franc'),
  LITHUANIA_LITAI=                Currency.new(:LTL, "U+004cU+0074", 'Lithuanian litas'),
  MACEDONIA_DENARS=               Currency.new(:MKD, "U+0434U+0435U+043d", 'Denar'),
  MALAYSIA_RINGGITS=              Currency.new(:MYR, "U+0052U+004d", 'Malaysian ringgit'),
  MAURITIUS_RUPEES=               Currency.new(:MUR, "U+20a8", 'Mauritius rupee'),
  MEXICO_PESOS=                   Currency.new(:MXN, DOLLAR_SIGN, 'Mexican peso'),
  MONGOLIA_TUGRIKS=               Currency.new(:MNT, "U+20ae", 'Tugrik'),
  MOZAMBIQUE_METICALS=            Currency.new(:MZN, "U+004dU+0054", 'Metical'),
  NAMIBIA_DOLLARS=                Currency.new(:NAD, DOLLAR_SIGN, 'Namibian dollar'),
  NEPAL_RUPEES=                   Currency.new(:NPR, "U+20a8", 'Nepalese rupee'),
  NETHERLANDS_ANTILLES_GUILDERS=  Currency.new(:ANG, "U+0192", 'Netherlands Antillean gulider'),
  NEW_ZEALAND_DOLLARS=            Currency.new(:NZD, DOLLAR_SIGN, 'New Zealand dollar'),
  NICARAGUA_CORDOBAS=             Currency.new(:NIO, "U+0043#{DOLLAR_SIGN}", 'Cordoba oro'),
  NIGERIA_NAIRAS=                 Currency.new(:NGN, "U+20a6", 'Naira'),
  NORWAY_KRONE=                   Currency.new(:NOK, "U+006bU+0072", 'Norwegian krone'),
  OMAN_RIALS=                     Currency.new(:OMR, "U+fdfc", 'Rial Omani'),
  PAKISTAN_RUPEES=                Currency.new(:PKR, "U+20a8", 'Pakistan rupee'),
  PANAMA_BALBOA=                  Currency.new(:PAB, "U+0042U+002fU+002e", 'Balboa'),
  PARAGUAY_GUARANI=               Currency.new(:PYG, "U+0047U+0073", 'Guarani'),
  PERU_NUEVOS_SOLES=              Currency.new(:PEN, "U+0053U+002fU+002e", 'Nuevo sol'),
  PHILIPPINES_PESOS=              Currency.new(:PHP, "U+0050U+0068U+0070", 'Philippine peso'),
  POLAND_ZLOTYCH=                 Currency.new(:PLN, "U+007aU+0142", 'Zloty'),
  QATAR_RIALS=                    Currency.new(:QAR, "U+fdfc", 'Qatari rial'),
  ROMANIA_NEW_LEI=                Currency.new(:RON, "U+006cU+0065U+0069", 'Romanian new leu'),
  RUSSIA_RUBLES=                  Currency.new(:RUB, "U+0440U+0443U+0432", 'Russian rouble'),
  SAINT_HELENA_POUNDS=            Currency.new(:SHP, POUND_SIGN, 'Saint Helena pound'),
  SAUDI_ARABIA_RIYALS=            Currency.new(:SAR, "U+fdfc", 'Saudi riyal'),
  SERBIA_DINARS=                  Currency.new(:RSD, "U+0414U+0438U+043dU+002e", 'Serbian dinar'),
  SEYCHELIES_RUPEES=              Currency.new(:SCR, "U+20a8", 'Seychelles rupee'),
  SINGAPORE_DOLLARS=              Currency.new(:SGD, DOLLAR_SIGN, 'Singapore dollar'),
  SOLOMON_ISLANDS_DOLLARS=        Currency.new(:SBD, DOLLAR_SIGN, 'Solomon Islands dollar'),
  SOMALIA_SHILLINGS=              Currency.new(:SOS, "U+0053", 'Somali shilling'),
  SOUTH_AFRICA_RAND=              Currency.new(:ZAR, "U+0052", 'South African rand'),
  SRI_LANKA_RUPEES=               Currency.new(:LKR, "U+20a8", 'Sri Lanka rupee'),
  SWEDEN_KRONOR=                  Currency.new(:SEK, "U+006bU+0072", 'Swedish krona/kronor'),
  SURINAME_DOLLARS=               Currency.new(:SRD, DOLLAR_SIGN, 'Surinam dollar'),
  SYRIA_POUNDS=                   Currency.new(:SYP, POUND_SIGN, 'Syrian pound'),
  TAIWAN_NEW_DOLLARS=             Currency.new(:TWD, "U+004eU+0054U+0024", 'New Taiwan dollar'),
  THAILAND_BAHT=                  Currency.new(:THB, "U+0e3f", 'Baht'),
  TRINIDAD_AND_TOBAGO_DOLLARS=    Currency.new(:TTD, "U+0054U+0054#{DOLLAR_SIGN}", 'Trinidad and Tobago dollar') ,
  TURKEY_LIRA=                    Currency.new(:TRY, "U+0054U+004c", 'Turkish lira'),
  TUVALU_DOLLARS=                 Currency.new(:TVD, DOLLAR_SIGN, 'Tuvalu dollar'),
  UKRAINE_HRYVNIA=                Currency.new(:UAH, "U+20b4", 'Hryvina'),
  URUGUAY_PESOS=                  Currency.new(:UYU, "#{DOLLAR_SIGN}U+0055", 'Peso Uruguayo'),
  UZBEKISTAN_SUMS=                Currency.new(:UZS, "U+043bU+0432", 'Uzbekistan som'),
  VENEZUELA_BOLIVARES_FUERTES=    Currency.new(:VEF, "U+0042U+0073", 'Venezuelan bolivar fuerte'),
  VIETNAM_DONG=                   Currency.new(:VND, "U+20ab", 'Vietnamese dong'),
  YEMEN_RIALS=                    Currency.new(:YER, "U+fdfc", 'Yemeni rial')
]
CURRENCY_BY_CODE =
Hash.new

Instance Method Summary collapse

Instance Method Details

#currency(code) ⇒ Object



127
128
129
# File 'lib/iso4217/currencies.rb', line 127

def currency(code)
  CURRENCY_BY_CODE[code.to_s]
end

#currency_code_for(country_code, default_when_currency_not_found = :NAC) ⇒ Object



40
41
42
# File 'lib/iso4217/iso4217.rb', line 40

def currency_code_for(country_code, default_when_currency_not_found= :NAC)
  currency_for(country_code, default_when_currency_not_found).code.to_s
end

#currency_for(country_code, default_when_currency_not_found = :NAC) ⇒ Object



36
37
38
# File 'lib/iso4217/iso4217.rb', line 36

def currency_for(country_code, default_when_currency_not_found= :NAC)
  COUNTRIES[country_code] || Currency.new(default_when_currency_not_found, GENERIC_CURRENCY_SIGN, 'unknown')
end

#currency_sign_for(country_code, default_when_currency_not_found = :NAC) ⇒ Object



44
45
46
# File 'lib/iso4217/iso4217.rb', line 44

def currency_sign_for(country_code, default_when_currency_not_found= :NAC)
  currency_for(country_code, default_when_currency_not_found).sign
end