Class Money::Currency
In: lib/money/currency.rb
Parent: Object

Represents a specific currency unit.

Methods

<=>   ==   code   decimal_places   decimal_places_cache   eql?   find   hash   inspect   new   register   stringified_keys   symbol_first?   table   to_currency   to_s   wrap  

Included Modules

Comparable

Classes and Modules

Class Money::Currency::UnknownCurrency

External Aliases

decimal_mark -> separator
thousands_separator -> delimiter

Attributes

decimal_mark  [R]  The decimal mark, or character used to separate the whole unit from the subunit.

@return [String]

html_entity  [R]  The html entity for the currency symbol

@return [String]

id  [R]  The symbol used to identify the currency, usually the lowercase iso_code attribute.

@return [Symbol]

iso_code  [R]  The international 3-letter code as defined by the ISO 4217 standard.

@return [String]

iso_numeric  [R]  The international 3-numeric code as defined by the ISO 4217 standard.

@return [String]

name  [R]  The currency name.

@return [String]

priority  [R]  A numerical value you can use to sort/group the currency list.

@return [Integer]

subunit  [R]  The name of the fractional monetary unit.

@return [String]

subunit_to_unit  [R]  The proportion between the unit and the subunit

@return [Integer]

symbol  [R]  The currency symbol (UTF-8 encoded).

@return [String]

symbol_first  [R]  Should the currency symbol precede the amount, or should it come after?

@return [boolean]

thousands_separator  [R]  The character used to separate thousands grouping of the whole unit.

@return [String]

Public Class methods

Cache decimal places for subunit_to_unit values. Common ones pre-cached.

Lookup a currency with given id an returns a Currency instance on success, nil otherwise.

@param [String, Symbol, to_s] id Used to look into table and retrieve the applicable attributes.

@return [Money::Currency]

@example

  Money::Currency.find(:eur) #=> #<Money::Currency id: eur ...>
  Money::Currency.find(:foo) #=> nil

Create a new Currency object.

@param [String, Symbol, to_s] id Used to look into table and retrieve

 the applicable attributes.

@return [Money::Currency]

@example

  Money::Currency.new(:usd) #=> #<Money::Currency id: usd ...>

List of known currencies.

monetary unit

The standard unit of value of a currency, as the dollar in the United States or the peso in Mexico. www.answers.com/topic/monetary-unit

fractional monetary unit, subunit

A monetary unit that is valued at a fraction (usually one hundredth) of the basic monetary unit www.answers.com/topic/fractional-monetary-unit-subunit

See en.wikipedia.org/wiki/List_of_circulating_currencies and search.cpan.org/~tnguyen/Locale-Currency-Format-1.28/Format.pm

Wraps the object in a Currency unless it‘s already a Currency object.

@param [Object] object The object to attempt and wrap as a Currency object.

@return [Money::Currency]

@example

  c1 = Money::Currency.new(:usd)
  Money::Currency.wrap(nil)   #=> nil
  Money::Currency.wrap(c1)    #=> #<Money::Currency id: usd ...>
  Money::Currency.wrap("usd") #=> #<Money::Currency id: usd ...>

Public Instance methods

Compares self with other_currency against the value of priority attribute.

@param [Money::Currency] other_currency The currency to compare to.

@return [-1,0,1] -1 if less than, 0 is equal to, 1 if greater than

@example

  c1 = Money::Currency.new(:usd)
  c2 = Money::Currency.new(:jpy)
  c1 <=> c2 #=> 1
  c2 <=> c1 #=> -1
  c1 <=> c1 #=> 0

Compares self with other_currency and returns true if the are the same or if their id attributes match.

@param [Money::Currency] other_currency The currency to compare to.

@return [Boolean]

@example

  c1 = Money::Currency.new(:usd)
  c2 = Money::Currency.new(:jpy)
  c1 == c1 #=> true
  c1 == c2 #=> false

Returns currency symbol or iso code for currencies with no symbol.

@return [String]

The number of decimal places needed.

@return [Integer]

Compares self with other_currency and returns true if the are the same or if their id attributes match.

@param [Money::Currency] other_currency The currency to compare to.

@return [Boolean]

@example

  c1 = Money::Currency.new(:usd)
  c2 = Money::Currency.new(:jpy)
  c1.eql? c1 #=> true
  c1.eql? c2 #=> false

Returns a Fixnum hash value based on the id attribute in order to use functions like & (intersection), group_by, etc.

@return [Fixnum]

@example

  Money::Currency.new(:usd).hash #=> 428936

Returns a human readable representation.

@return [String]

@example

  Money::Currency.new(:usd) #=> #<Currency id: usd ...>

Conversation to self.

@return [self]

Returns a string representation corresponding to the upcase id attribute.

-– DEV: id.to_s.upcase corresponds to iso_code but don‘t use ISO_CODE for consistency.

@return [String]

@example

  Money::Currency.new(:usd).to_s #=> "USD"
  Money::Currency.new(:eur).to_s #=> "EUR"

[Validate]