Class: BigMoney::Currency

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/big_money/currency.rb,
lib/big_money/currency/iso4217.rb

Constant Summary collapse

AED =
Currency.register(%q{AED}, 2, %q{United Arab Emirates dirham})
AFN =
Currency.register(%q{AFN}, 2, %q{Afghani})
ALL =
Currency.register(%q{ALL}, 2, %q{Lek})
AMD =
Currency.register(%q{AMD}, 0, %q{Armenian dram})
ANG =
Currency.register(%q{ANG}, 2, %q{Netherlands Antillean guilder})
AOA =
Currency.register(%q{AOA}, 1, %q{Kwanza})
ARS =
Currency.register(%q{ARS}, 2, %q{Argentine peso})
AUD =
Currency.register(%q{AUD}, 2, %q{Australian dollar})
AWG =
Currency.register(%q{AWG}, 2, %q{Aruban guilder})
AZN =
Currency.register(%q{AZN}, 2, %q{Azerbaijanian manat})
BAM =
Currency.register(%q{BAM}, 2, %q{Convertible marks})
BBD =
Currency.register(%q{BBD}, 2, %q{Barbados dollar})
BDT =
Currency.register(%q{BDT}, 2, %q{Bangladeshi taka})
BGN =
Currency.register(%q{BGN}, 2, %q{Bulgarian lev})
BHD =
Currency.register(%q{BHD}, 3, %q{Bahraini dinar})
BIF =
Currency.register(%q{BIF}, 0, %q{Burundian franc})
BMD =
Currency.register(%q{BMD}, 2, %q{Bermudian dollar})
BND =
Currency.register(%q{BND}, 2, %q{Brunei dollar})
BOB =
Currency.register(%q{BOB}, 2, %q{Boliviano})
BOV =
Currency.register(%q{BOV}, 2, %q{Bolivian Mvdol (funds code)})
BRL =
Currency.register(%q{BRL}, 2, %q{Brazilian real})
BSD =
Currency.register(%q{BSD}, 2, %q{Bahamian dollar})
BTN =
Currency.register(%q{BTN}, 2, %q{Ngultrum})
BWP =
Currency.register(%q{BWP}, 2, %q{Pula})
BYR =
Currency.register(%q{BYR}, 0, %q{Belarusian ruble})
BZD =
Currency.register(%q{BZD}, 2, %q{Belize dollar})
CAD =
Currency.register(%q{CAD}, 2, %q{Canadian dollar})
CDF =
Currency.register(%q{CDF}, 2, %q{Franc Congolais})
CHE =
Currency.register(%q{CHE}, 2, %q{WIR eurocomplementary currency})
CHF =
Currency.register(%q{CHF}, 2, %q{Swiss franc})
CHW =
Currency.register(%q{CHW}, 2, %q{WIR franccomplementary currency})
CLF =
Currency.register(%q{CLF}, 0, %q{Unidad de Fomento})
CLP =
Currency.register(%q{CLP}, 0, %q{Chilean peso})
CNY =
Currency.register(%q{CNY}, 1, %q{Chinese Yuan})
COP =
Currency.register(%q{COP}, 0, %q{Colombian peso})
COU =
Currency.register(%q{COU}, 2, %q{Unidad de Valor Real})
CRC =
Currency.register(%q{CRC}, 2, %q{Costa Rican colon})
CUC =
Currency.register(%q{CUC}, 2, %q{Cuban convertible peso})
CUP =
Currency.register(%q{CUP}, 2, %q{Cuban peso})
CVE =
Currency.register(%q{CVE}, 2, %q{Cape Verde escudo})
CZK =
Currency.register(%q{CZK}, 2, %q{Czech Koruna})
DJF =
Currency.register(%q{DJF}, 0, %q{Djibouti franc})
DKK =
Currency.register(%q{DKK}, 2, %q{Danish krone})
DOP =
Currency.register(%q{DOP}, 2, %q{Dominican peso})
DZD =
Currency.register(%q{DZD}, 2, %q{Algerian dinar})
EEK =
Currency.register(%q{EEK}, 2, %q{Kroon})
EGP =
Currency.register(%q{EGP}, 2, %q{Egyptian pound})
ERN =
Currency.register(%q{ERN}, 2, %q{Nakfa})
ETB =
Currency.register(%q{ETB}, 2, %q{Ethiopian birr})
EUR =
Currency.register(%q{EUR}, 2, %q{euro})
FJD =
Currency.register(%q{FJD}, 2, %q{Fiji dollar})
FKP =
Currency.register(%q{FKP}, 2, %q{Falkland Islands pound})
GBP =
Currency.register(%q{GBP}, 2, %q{Pound sterling})
GEL =
Currency.register(%q{GEL}, 2, %q{Lari})
GHS =
Currency.register(%q{GHS}, 2, %q{Cedi})
GIP =
Currency.register(%q{GIP}, 2, %q{Gibraltar pound})
GMD =
Currency.register(%q{GMD}, 2, %q{Dalasi})
GNF =
Currency.register(%q{GNF}, 0, %q{Guinea franc})
GTQ =
Currency.register(%q{GTQ}, 2, %q{Quetzal})
GYD =
Currency.register(%q{GYD}, 2, %q{Guyana dollar})
HKD =
Currency.register(%q{HKD}, 2, %q{Hong Kong dollar})
HNL =
Currency.register(%q{HNL}, 2, %q{Lempira})
HRK =
Currency.register(%q{HRK}, 2, %q{Croatian kuna})
HTG =
Currency.register(%q{HTG}, 2, %q{Haiti gourde})
HUF =
Currency.register(%q{HUF}, 2, %q{Forint})
IDR =
Currency.register(%q{IDR}, 0, %q{Rupiah})
ILS =
Currency.register(%q{ILS}, 2, %q{Israeli new sheqel})
INR =
Currency.register(%q{INR}, 2, %q{Indian rupee})
IQD =
Currency.register(%q{IQD}, 0, %q{Iraqi dinar})
IRR =
Currency.register(%q{IRR}, 0, %q{Iranian rial})
ISK =
Currency.register(%q{ISK}, 0, %q{Iceland krona})
JMD =
Currency.register(%q{JMD}, 2, %q{Jamaican dollar})
JOD =
Currency.register(%q{JOD}, 3, %q{Jordanian dinar})
JPY =
Currency.register(%q{JPY}, 0, %q{Japanese yen})
KES =
Currency.register(%q{KES}, 2, %q{Kenyan shilling})
KGS =
Currency.register(%q{KGS}, 2, %q{Som})
KHR =
Currency.register(%q{KHR}, 0, %q{Riel})
KMF =
Currency.register(%q{KMF}, 0, %q{Comoro franc})
KPW =
Currency.register(%q{KPW}, 0, %q{North Korean won})
KRW =
Currency.register(%q{KRW}, 0, %q{South Korean won})
KWD =
Currency.register(%q{KWD}, 3, %q{Kuwaiti dinar})
KYD =
Currency.register(%q{KYD}, 2, %q{Cayman Islands dollar})
KZT =
Currency.register(%q{KZT}, 2, %q{Tenge})
LAK =
Currency.register(%q{LAK}, 0, %q{Kip})
LBP =
Currency.register(%q{LBP}, 0, %q{Lebanese pound})
LKR =
Currency.register(%q{LKR}, 2, %q{Sri Lanka rupee})
LRD =
Currency.register(%q{LRD}, 2, %q{Liberian dollar})
LSL =
Currency.register(%q{LSL}, 2, %q{Lesotho loti})
LTL =
Currency.register(%q{LTL}, 2, %q{Lithuanian litas})
LVL =
Currency.register(%q{LVL}, 2, %q{Latvian lats})
LYD =
Currency.register(%q{LYD}, 3, %q{Libyan dinar})
MAD =
Currency.register(%q{MAD}, 2, %q{Moroccan dirham})
MDL =
Currency.register(%q{MDL}, 2, %q{Moldovan leu})
MGA =
Currency.register(%q{MGA}, 0, %q{Malagasy ariary})
MKD =
Currency.register(%q{MKD}, 2, %q{Denar})
MMK =
Currency.register(%q{MMK}, 0, %q{Kyat})
MNT =
Currency.register(%q{MNT}, 2, %q{Tugrik})
MOP =
Currency.register(%q{MOP}, 1, %q{Pataca})
MRO =
Currency.register(%q{MRO}, 0, %q{Ouguiya})
MUR =
Currency.register(%q{MUR}, 2, %q{Mauritius rupee})
MVR =
Currency.register(%q{MVR}, 2, %q{Rufiyaa})
MWK =
Currency.register(%q{MWK}, 2, %q{Kwacha})
MXN =
Currency.register(%q{MXN}, 2, %q{Mexican peso})
MXV =
Currency.register(%q{MXV}, 2, %q{Mexican Unidad de Inversion})
MYR =
Currency.register(%q{MYR}, 2, %q{Malaysian ringgit})
MZN =
Currency.register(%q{MZN}, 2, %q{Metical})
NAD =
Currency.register(%q{NAD}, 2, %q{Namibian dollar})
NGN =
Currency.register(%q{NGN}, 2, %q{Naira})
NIO =
Currency.register(%q{NIO}, 2, %q{Cordoba oro})
NOK =
Currency.register(%q{NOK}, 2, %q{Norwegian krone})
NPR =
Currency.register(%q{NPR}, 2, %q{Nepalese rupee})
NZD =
Currency.register(%q{NZD}, 2, %q{New Zealand dollar})
OMR =
Currency.register(%q{OMR}, 3, %q{Rial Omani})
PAB =
Currency.register(%q{PAB}, 2, %q{Balboa})
PEN =
Currency.register(%q{PEN}, 2, %q{Nuevo sol})
PGK =
Currency.register(%q{PGK}, 2, %q{Kina})
PHP =
Currency.register(%q{PHP}, 2, %q{Philippine peso})
PKR =
Currency.register(%q{PKR}, 2, %q{Pakistan rupee})
PLN =
Currency.register(%q{PLN}, 2, %q{Złoty})
PYG =
Currency.register(%q{PYG}, 0, %q{Guarani})
QAR =
Currency.register(%q{QAR}, 2, %q{Qatari rial})
RON =
Currency.register(%q{RON}, 2, %q{Romanian new leu})
RSD =
Currency.register(%q{RSD}, 2, %q{Serbian dinar})
RUB =
Currency.register(%q{RUB}, 2, %q{Russian rouble})
RWF =
Currency.register(%q{RWF}, 0, %q{Rwanda franc})
SAR =
Currency.register(%q{SAR}, 2, %q{Saudi riyal})
SBD =
Currency.register(%q{SBD}, 2, %q{Solomon Islands dollar})
SCR =
Currency.register(%q{SCR}, 2, %q{Seychelles rupee})
SDG =
Currency.register(%q{SDG}, 2, %q{Sudanese pound})
SEK =
Currency.register(%q{SEK}, 2, %q{Swedish krona})
SGD =
Currency.register(%q{SGD}, 2, %q{Singapore dollar})
SHP =
Currency.register(%q{SHP}, 2, %q{Saint Helena pound})
SLL =
Currency.register(%q{SLL}, 0, %q{Leone})
SOS =
Currency.register(%q{SOS}, 2, %q{Somali shilling})
SRD =
Currency.register(%q{SRD}, 2, %q{Surinam dollar})
STD =
Currency.register(%q{STD}, 0, %q{Dobra})
SYP =
Currency.register(%q{SYP}, 2, %q{Syrian pound})
SZL =
Currency.register(%q{SZL}, 2, %q{Lilangeni})
THB =
Currency.register(%q{THB}, 2, %q{Baht})
TJS =
Currency.register(%q{TJS}, 2, %q{Somoni})
TMT =
Currency.register(%q{TMT}, 2, %q{Manat})
TND =
Currency.register(%q{TND}, 3, %q{Tunisian dinar})
TOP =
Currency.register(%q{TOP}, 2, %q{Pa'anga})
TRY =
Currency.register(%q{TRY}, 2, %q{Turkish lira})
TTD =
Currency.register(%q{TTD}, 2, %q{Trinidad and Tobago dollar})
TWD =
Currency.register(%q{TWD}, 1, %q{New Taiwan dollar})
TZS =
Currency.register(%q{TZS}, 2, %q{Tanzanian shilling})
UAH =
Currency.register(%q{UAH}, 2, %q{Hryvnia})
UGX =
Currency.register(%q{UGX}, 0, %q{Uganda shilling})
USD =
Currency.register(%q{USD}, 2, %q{US dollar})
USN =
Currency.register(%q{USN}, 2, %q{United States dollar (next day) (funds code)})
USS =
Currency.register(%q{USS}, 2, %q{who?})
UYU =
Currency.register(%q{UYU}, 2, %q{Peso Uruguayo})
UZS =
Currency.register(%q{UZS}, 2, %q{Uzbekistan som})
VEF =
Currency.register(%q{VEF}, 2, %q{Venezuelan bolívar fuerte})
VND =
Currency.register(%q{VND}, 0, %q{Vietnamese đồng})
VUV =
Currency.register(%q{VUV}, 0, %q{Vatu})
WST =
Currency.register(%q{WST}, 2, %q{Samoan tala})
XAF =
Currency.register(%q{XAF}, 0, %q{CFA franc BEAC})
XAG =
Currency.register(%q{XAG}, 0, %q{Silvertroy ounce})
XAU =
Currency.register(%q{XAU}, 0, %q{Goldtroy ounce})
XBA =
Currency.register(%q{XBA}, 0, %q{European Composite Unit})
XBB =
Currency.register(%q{XBB}, 0, %q{European Monetary Unit})
XBC =
Currency.register(%q{XBC}, 0, %q{European Unit of Account 9})
XBD =
Currency.register(%q{XBD}, 0, %q{European Unit of Account 17})
XCD =
Currency.register(%q{XCD}, 2, %q{East Caribbean dollar})
XDR =
Currency.register(%q{XDR}, 0, %q{Special Drawing Rights})
XFU =
Currency.register(%q{XFU}, 0, %q{UIC franc})
XOF =
Currency.register(%q{XOF}, 0, %q{CFA Franc BCEAO})
XPD =
Currency.register(%q{XPD}, 0, %q{Palladiumtroy ounce})
XPF =
Currency.register(%q{XPF}, 0, %q{CFP franc})
XPT =
Currency.register(%q{XPT}, 0, %q{Platinumtroy ounce})
XTS =
Currency.register(%q{XTS}, 0, %q{Code reserved for testing purposes})
XXX =
Currency.register(%q{XXX}, 0, %q{No currency})
YER =
Currency.register(%q{YER}, 0, %q{Yemeni rial})
ZAR =
Currency.register(%q{ZAR}, 2, %q{South African rand})
ZMK =
Currency.register(%q{ZMK}, 0, %q{Kwacha})
ZWL =
Currency.register(%q{ZWL}, 2, %q{Zimbabwe dollar})

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, offset, name) ⇒ Currency

– TODO: Validate.



25
26
27
# File 'lib/big_money/currency.rb', line 25

def initialize(code, offset, name)
  @code, @offset, @name = code.to_s.upcase, offset, name
end

Instance Attribute Details

#codeObject Also known as: to_s

Returns the value of attribute code.



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

def code
  @code
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#offsetObject

Returns the value of attribute offset.



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

def offset
  @offset
end

Class Method Details

.allObject



45
46
47
# File 'lib/big_money/currency.rb', line 45

def all
  @@all ||= Set.new
end

.defaultObject



30
31
32
33
# File 'lib/big_money/currency.rb', line 30

def default
  raise "No default currency has been set. See BigMoney::Currency." unless default?
  @@default
end

.default=(currency) ⇒ Object

Raises:

  • (TypeError)


35
36
37
38
39
# File 'lib/big_money/currency.rb', line 35

def default=(currency)
  raise TypeError.new("Expected kind of BigMoney::Currency but got #{currency.class}.") \
    unless currency.kind_of?(Currency)
  @@default = currency
end

.default?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/big_money/currency.rb', line 41

def default?
  defined? @@default
end

.find(currency) ⇒ Object

Find an existing currency module by Object, Symbol or String.

Examples

AUD = BigMoney::Currency.new(:aud, 2, 'Australian Dollar')

BigMoney::Currency.find(:aud)
BigMoney::Currency.find('aud')
BigMoney::Currency.find('AUD')
BigMoney::Currency.find(AUD)


59
60
61
62
63
64
65
66
# File 'lib/big_money/currency.rb', line 59

def find(currency)
  if currency.is_a?(self)
    currency
  else
    currency = currency.to_s.upcase
    all.find{|c| c.code == currency}
  end
end

.register(*args) ⇒ Object



68
69
70
71
# File 'lib/big_money/currency.rb', line 68

def register(*args)
  self.all << currency = new(*args).freeze
  currency
end

Instance Method Details

#<=>(rvalue) ⇒ Object



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

def <=>(rvalue)
  self.class == rvalue.class ? (code <=> rvalue.code) || 0 : nil
end

#eql?(rvalue) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


14
15
16
# File 'lib/big_money/currency.rb', line 14

def eql?(rvalue)
  self.class.equal?(rvalue.class) && code == rvalue.code
end

#hashObject



10
11
12
# File 'lib/big_money/currency.rb', line 10

def hash
  code.hash
end