class Money::Currency

Overview

Represents a specific currency unit.

See ISO 4217.

Included Modules

Extended Modules

Defined in:

money/currency.cr
money/currency/enumeration.cr
money/currency/json.cr
money/currency/loader.cr
money/currency/rate.cr
money/currency/rate_store.cr
money/currency/rate_store/memory.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(pull : JSON::PullParser) #

[View source]
def self.new(*, priority : Int32 | Nil = nil, iso_numeric : UInt32 | Nil = nil, code : String, name : Nil | String = nil, symbol : Nil | String = nil, disambiguate_symbol : Nil | String = nil, alternate_symbols : Nil | Array(String) = nil, subunit : Nil | String = nil, subunit_to_unit : UInt64, symbol_first : Bool | Nil = nil, html_entity : Nil | String = nil, decimal_mark : Nil | String = nil, thousands_separator : Nil | String = nil, smallest_denomination : UInt32 | Nil = nil) #

[View source]
def self.wrap(value : String | Symbol | Currency) : Currency #

Wraps the value in a Currency object.

c1 = Money::Currency.find(:usd)
Money::Currency.wrap?(c1)    # => #<Money::Currency @id="usd">
Money::Currency.wrap?("usd") # => #<Money::Currency @id="usd">
Money::Currency.wrap?(:usd)  # => #<Money::Currency @id="usd">
Money::Currency.wrap?(:foo)  # => nil

[View source]

Class Method Detail

def self.register(currency : Currency) #

[View source]
def self.table : Hash(String, Currency) #

List of known currencies.


[View source]
def self.unregister(currency : Currency) #

[View source]
def self.unregister(currency_code : String | Symbol) #

[View source]
def self.wrap?(value : String | Symbol | Currency) : Currency | Nil #

Wraps the value in a Currency object.

c1 = Money::Currency.find(:usd)
Money::Currency.wrap?(c1)    # => #<Money::Currency @id="usd">
Money::Currency.wrap?("usd") # => #<Money::Currency @id="usd">
Money::Currency.wrap?(:usd)  # => #<Money::Currency @id="usd">
Money::Currency.wrap?(:foo)  # => nil

[View source]

Instance Method Detail

def <=>(other : Currency) : Int32 #

Compares self with other currency against the value of #priority and #id attributes.


[View source]
def <=>(other : String | Symbol) : Int32 #

Compares self with other currency against the value of id` attribute.


[View source]
def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def alternate_symbols : Array(String) | Nil #

[View source]
def code : String #

[View source]
def decimal_mark : String | Nil #

[View source]
def decimal_places : Int32 #

Alias of #exponent.


[View source]
def disambiguate_symbol : String | Nil #

[View source]
def exponent : Int32 #

Returns the relation between subunit and unit as a base 10 exponent.

NOTE MGA and MRU are exceptions and are rounded to 1.

See Active_codes.


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def html_entity : String | Nil #

[View source]
def id : String #

Currency ID, for time being lower-cased #code.


[View source]
def iso? #

Returns true if iso currency.

See #iso_numeric.


[View source]
def iso_numeric : UInt32 | Nil #

[View source]
def name : String | Nil #

[View source]
def priority : Int32 | Nil #

[View source]
def smallest_denomination : UInt32 | Nil #

[View source]
def subunit : String | Nil #

[View source]
def subunit_to_unit : UInt64 #

[View source]
def symbol : String | Nil #

[View source]
def symbol_first? : Bool | Nil #

[View source]
def thousands_separator : String | Nil #

[View source]
def to_s(io : IO) : Nil #

Appends a string representation corresponding to the #code property to the given io.

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

[View source]