Class: Money::NullCurrency
- Inherits:
-
Object
- Object
- Money::NullCurrency
- Defined in:
- lib/money/null_currency.rb
Overview
A placeholder currency for instances where no actual currency is available, as defined by ISO4217. You should rarely, if ever, need to use this directly. It’s here mostly for backwards compatibility and for that reason behaves like a dollar, which is how this gem worked before the introduction of currency.
Here follows a list of preferred alternatives over using Money with NullCurrency:
For comparisons where you don’t know the currency beforehand, you can use Numeric predicate methods like #positive?/#negative?/#zero?/#nonzero?. Comparison operators with Numeric (==, !=, <=, =>, <, >) work as well.
Money with NullCurrency has behaviour that may surprise you, such as database validations or GraphQL enum not allowing the string representation of NullCurrency. Prefer using Money.new(0, currency) where possible, as this sidesteps these issues and provides additional currency check safeties.
Unlike other currencies, it is allowed to calculate a Money object with NullCurrency with another currency. The resulting Money object will have the other currency.
Instance Attribute Summary collapse
-
#decimal_mark ⇒ Object
readonly
Returns the value of attribute decimal_mark.
-
#disambiguate_symbol ⇒ Object
readonly
Returns the value of attribute disambiguate_symbol.
-
#iso_code ⇒ Object
readonly
Returns the value of attribute iso_code.
-
#iso_numeric ⇒ Object
readonly
Returns the value of attribute iso_numeric.
-
#minor_units ⇒ Object
readonly
Returns the value of attribute minor_units.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#smallest_denomination ⇒ Object
readonly
Returns the value of attribute smallest_denomination.
-
#subunit_symbol ⇒ Object
readonly
Returns the value of attribute subunit_symbol.
-
#subunit_to_unit ⇒ Object
readonly
Returns the value of attribute subunit_to_unit.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #compatible?(other) ⇒ Boolean
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize ⇒ NullCurrency
constructor
A new instance of NullCurrency.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ NullCurrency
Returns a new instance of NullCurrency.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/money/null_currency.rb', line 39 def initialize @symbol = '$' @disambiguate_symbol = nil @subunit_symbol = nil @iso_code = 'XXX' @iso_numeric = '999' @name = 'No Currency' @smallest_denomination = 1 @subunit_to_unit = 100 @minor_units = 2 @decimal_mark = '.' freeze end |
Instance Attribute Details
#decimal_mark ⇒ Object (readonly)
Returns the value of attribute decimal_mark.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def decimal_mark @decimal_mark end |
#disambiguate_symbol ⇒ Object (readonly)
Returns the value of attribute disambiguate_symbol.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def disambiguate_symbol @disambiguate_symbol end |
#iso_code ⇒ Object (readonly)
Returns the value of attribute iso_code.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def iso_code @iso_code end |
#iso_numeric ⇒ Object (readonly)
Returns the value of attribute iso_numeric.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def iso_numeric @iso_numeric end |
#minor_units ⇒ Object (readonly)
Returns the value of attribute minor_units.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def minor_units @minor_units end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def name @name end |
#smallest_denomination ⇒ Object (readonly)
Returns the value of attribute smallest_denomination.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def smallest_denomination @smallest_denomination end |
#subunit_symbol ⇒ Object (readonly)
Returns the value of attribute subunit_symbol.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def subunit_symbol @subunit_symbol end |
#subunit_to_unit ⇒ Object (readonly)
Returns the value of attribute subunit_to_unit.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def subunit_to_unit @subunit_to_unit end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
36 37 38 |
# File 'lib/money/null_currency.rb', line 36 def symbol @symbol end |
Instance Method Details
#compatible?(other) ⇒ Boolean
53 54 55 |
# File 'lib/money/null_currency.rb', line 53 def compatible?(other) other.is_a?(Currency) || other.is_a?(NullCurrency) end |
#eql?(other) ⇒ Boolean Also known as: ==
57 58 59 |
# File 'lib/money/null_currency.rb', line 57 def eql?(other) self.class == other.class && iso_code == other.iso_code end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/money/null_currency.rb', line 61 def to_s '' end |