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/exchange.cr
money/currency/exchange/single_currency.cr
money/currency/json.cr
money/currency/loader.cr
money/currency/rate.cr
money/currency/rate_provider.cr
money/currency/rate_provider/abstract_api.cr
money/currency/rate_provider/coinlayer.cr
money/currency/rate_provider/compound.cr
money/currency/rate_provider/currency_api.cr
money/currency/rate_provider/currency_beacon.cr
money/currency/rate_provider/currency_layer.cr
money/currency/rate_provider/ecb.cr
money/currency/rate_provider/exchange_rate_api.cr
money/currency/rate_provider/fixer.cr
money/currency/rate_provider/float_rates.cr
money/currency/rate_provider/freecurrency_api.cr
money/currency/rate_provider/fx_feed.cr
money/currency/rate_provider/fx_rates_api.cr
money/currency/rate_provider/http.cr
money/currency/rate_provider/metalprice_api.cr
money/currency/rate_provider/money_morph.cr
money/currency/rate_provider/null.cr
money/currency/rate_provider/open_exchange_rates.cr
money/currency/rate_provider/uni_rate_api.cr
money/currency/rate_store.cr
money/currency/rate_store/file.cr
money/currency/rate_store/memory.cr
money/currency/type.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

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

[View source]
def self.new(*, type : Money::Currency::Type | Nil = nil, priority : Int32 | Nil = nil, iso_numeric : Int32 | 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, decimal_mark : Nil | String = nil, thousands_separator : Nil | String = nil, smallest_denomination : Int32 | Nil = nil) #

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

Registers a new currency.


[View source]

Class Method Detail

def self.crypto : Array(Currency) #

Returns an array of currencies of type Crypto.


[View source]
def self.fiat : Array(Currency) #

Returns an array of currencies of type Fiat.


[View source]
def self.metal : Array(Currency) #

Returns an array of currencies of type Metal.


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

List of known currencies.


[View source]
def self.reset! : Nil #

Resets all registered currencies to their defaults.


[View source]
def self.unregister(currency : String | Symbol | Currency) : Currency | Nil #

Unregisters a currency.


[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 : self) #
Description copied from class Reference

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


def alternate_symbols : Array(String) | Nil #

Alternate symbols.


[View source]
def cents_based? : Bool #

Returns true if a subunit is cents-based.

Money::Currency.find(:usd).cents_based? # => true
Money::Currency.find(:btc).cents_based? # => false

[View source]
def code : String #

Currency code.


[View source]
def crypto? : Bool #

Returns true if the currency #type is Crypto, otherwise false.


[View source]
def decimal_mark : String | Nil #

Decimal mark.


[View source]
def decimal_places : Int32 #

Alias of #exponent.


[View source]
def disambiguate_symbol : String | Nil #

Disambiguation symbol.


[View source]
def exponent : Int32 #

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

Money::Currency.find(:usd).exponent # => 2
Money::Currency.find(:btc).exponent # => 8

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

See Active_codes.


[View source]
def fiat? : Bool #

Returns true if the currency #type is Fiat, otherwise false.


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

See Object#hash(hasher)


def id : String #

Currency ID (lower-cased #code).


[View source]
def iso? : Bool #

Returns true if iso currency.

Money::Currency.find(:usd).iso? # => true
Money::Currency.find(:btc).iso? # => false

See also #iso_numeric.


[View source]
def iso_numeric : Int32 | Nil #

ISO 4217 numeric code.


[View source]
def metal? : Bool #

Returns true if the currency #type is Metal, otherwise false.


[View source]
def name : String | Nil #

Currency name.


[View source]
def priority : Int32 | Nil #

Currency priority (used for sorting).


[View source]
def smallest_denomination : Int32 | Nil #

Smallest denomination.


[View source]
def subunit : String | Nil #

Currency subunit.


[View source]
def subunit_to_unit : UInt64 #

Subunit to unit value.


[View source]
def symbol : String | Nil #

Currency symbol.


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

Should the symbol be placed before the amount?


[View source]
def thousands_separator : String | Nil #

Thousands separator.


[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(:btc).to_s # => "BTC"

[View source]
def type : Type | Nil #

Currency type.


[View source]