Class: Mint::Money
- Inherits:
-
Object
- Object
- Mint::Money
- Includes:
- Comparable
- Defined in:
- lib/minting/mint/i18n.rb,
lib/minting/money/clamp.rb,
lib/minting/money/money.rb,
lib/minting/money/coercion.rb,
lib/minting/money/comparable.rb,
lib/minting/money/conversion.rb,
lib/minting/money/format/to_s.rb,
lib/minting/money/constructors.rb,
lib/minting/money/allocation/split.rb,
lib/minting/money/format/formatting.rb,
lib/minting/money/arithmetics/methods.rb,
lib/minting/money/allocation/allocation.rb,
lib/minting/money/arithmetics/operators.rb
Overview
:nodoc:
Constant Summary collapse
- DEFAULT_FORMAT =
The default display format pattern for formatting monetary values. Uses
%<symbol>sfor the currency symbol and%<amount>ffor the rounded amount. '%<symbol>s%<amount>f'- PRESETS =
{ amount: { format: '%<amount>f' }, accounting: { format: { negative: '(%<symbol>s%<amount>f)' } }, european: { format: '%<amount>f %<symbol>s', decimal: ',', thousand: '.' }, currency: { format: '%<currency>s %<amount>f' } }.freeze
- THOUSAND_RE =
/(\d)(?=(\d{3})+\z)/
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
Class Method Summary collapse
-
.compile_formatter(format_hash, currency, decimal, thousand) ⇒ Object
Builds and returns a lambda that formats amounts for a fixed [format_config, currency, decimal, thousand] combination.
-
.compile_templates(format_hash, subunit) ⇒ Object
Build each sign template with subunit precision baked in, returning a frozen Hash of templates keyed by sign (:positive, :negative, :zero).
- .compiled_formatters ⇒ Object
-
.from(amount, currency) ⇒ Money
Creates a new Money immutable object with the specified amount and currency.
-
.from_subunits(subunits, currency) ⇒ Money
Builds a Money from a subunit (smallest-unit) Integer amount.
-
.no_currency(amount) ⇒ Money
Creates a new Money without a currency (ISO 4217 XXX — "No Currency").
-
.parse(input, currency = nil) ⇒ Money?
Parses a human-readable money string into a Money object.
-
.parse!(input, currency = nil) ⇒ Money
Like Money.parse but raises on failure.
-
.zero(currency) ⇒ Money
Returns a frozen zero Money in the given currency.
Instance Method Summary collapse
-
#*(multiplicand) ⇒ Money
Performs multiplication of the monetary value by a standard scalar Numeric.
-
#**(exponent) ⇒ Money
Performs exponentiation of the monetary value by a standard scalar Numeric.
-
#+(addend) ⇒ Money
Performs addition with another Money instance or standard zero Numeric.
-
#-(subtrahend) ⇒ Money
Performs subtraction with another Money instance or standard zero Numeric.
-
#-@ ⇒ Money
Unary negation operator.
-
#/(divisor) ⇒ Money, Numeric
Performs division of the monetary value by a scalar Numeric or identical currency Money.
- #<=>(other) ⇒ Object private
-
#==(other) ⇒ Object
private
True if both are zero, or both have same amount and same currency.
-
#abs ⇒ Money
Returns the absolute value of the monetary amount as a new Money instance.
-
#allocate(proportions) ⇒ Array<Money>
Proportionally allocates the monetary amount among a list of ratios.
-
#clamp(min_or_range, max = nil) ⇒ Money
Constrains
selfto the inclusive range [+min+, +max+]. -
#coerce(other) ⇒ Array(CoercedNumber, Money)
private
Allows Money to interact seamlessly as the right-hand operand in Numeric arithmetic.
-
#copy_with(amount:) ⇒ Money
Returns a new Money object with the specified amount, or self if unchanged.
-
#currency_code ⇒ String
Returns the ISO 3-letter currency code string.
-
#eql?(other) ⇒ Boolean
private
Strict equality — both amount and currency must match exactly.
-
#format(preset = nil, format: nil, decimal: nil, thousand: nil, width: nil) ⇒ String
(also: #to_fs)
Formats money as a string with customizable format, thousand delimiter, and decimal.
-
#fractional ⇒ Object
Returns the fractional part of the amount.
-
#hash ⇒ Integer
Generates a stable hash key for Money instances.
-
#inspect ⇒ String
Returns a standard developer-oriented string inspection of the Money object.
-
#mint(new_amount) ⇒ Money
deprecated
Deprecated.
Use #copy_with instead. Will be removed in v2.
-
#negative? ⇒ Boolean
Returns true if the monetary amount is less than zero.
-
#nonzero? ⇒ self?
private
Self if amount is non-zero, nil otherwise.
-
#positive? ⇒ Boolean
Returns true if the monetary amount is greater than zero.
-
#same_currency?(other) ⇒ Boolean
private
Helper method to verify if another Money has the identical currency.
-
#split(slices) ⇒ Array<Money>
Splits the monetary amount into a given quantity of equal parts.
-
#subunits ⇒ Integer
Returns the monetary amount expressed in the currency's smallest unit (fractional units).
-
#succ ⇒ Money
Returns the successor of the Money instance by adding the minimum possible subunit amount.
-
#to_d ⇒ BigDecimal
private
Converts the monetary amount to a BigDecimal object.
-
#to_f ⇒ Float
private
Converts the monetary amount to a standard float.
-
#to_hash ⇒ Hash
private
Returns a Hash representation of the money instance.
-
#to_html(format = DEFAULT_FORMAT) ⇒ String
private
Renders a safe HTML5
<data>element containing the formatted currency. -
#to_i ⇒ Integer
private
Truncates and converts the monetary amount to an Integer.
-
#to_json(*_args) ⇒ String
private
Serializes the money instance to a standard JSON object containing the amount and currency.
-
#to_r ⇒ Rational
private
Returns the exact internal Rational representation of the monetary amount.
- #to_s ⇒ Object
-
#zero? ⇒ Boolean
private
True if amount is zero.
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
20 21 22 |
# File 'lib/minting/money/money.rb', line 20 def amount @amount end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
20 21 22 |
# File 'lib/minting/money/money.rb', line 20 def currency @currency end |
Class Method Details
.compile_formatter(format_hash, currency, decimal, thousand) ⇒ Object
Builds and returns a lambda that formats amounts for a fixed [format_config, currency, decimal, thousand] combination. The lambda is cached by compiled_formatters.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/minting/money/format/formatting.rb', line 39 def self.compile_formatter(format_hash, currency, decimal, thousand) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity subunit = currency.subunit has_decimal_substitution = decimal != '.' escaped_decimal = Regexp.escape(decimal) has_thousand_separator = thousand && !thousand.empty? templates = compile_templates(format_hash, subunit) positive_template, negative_template, zero_template = templates # Detect whether templates use %<fractional> and/or %<d-symbol> all_templates = templates.compact.join needs_fractional = all_templates.include?('%<fractional>') needs_integral = all_templates.include?('%<amount>') || all_templates.include?('%<integral>') multiplier = currency.fractional_multiplier symbol = currency.symbol args = { currency: currency.code, dsymbol: currency.disambiguate_symbol || symbol, symbol: symbol } lambda do |amount| format_template = if negative_template && amount < 0 amount = -amount negative_template elsif zero_template && amount == 0 zero_template else positive_template end args[:amount] = amount args[:integral] = amount.to_i args[:fractional] = ((amount.abs % 1) * multiplier).to_i if needs_fractional result = Kernel.format(format_template, **args) result.gsub!(/(?<=\d)\.(?=\d)/, decimal) if has_decimal_substitution if needs_integral && has_thousand_separator && (amount >= 1000 || amount <= -1000) # Split on the decimal separator between digits only — symbols may contain '.' (e.g. د.إ). parts = result.split(/(?<=\d)#{escaped_decimal}(?=\d)/, 2) # Insert the thousands delimiter before each run of 3 digits from the right. parts[0].gsub!(/(\d)(?=(?:\d{3})+(?:[^\d]|$))/) { Regexp.last_match(1) + thousand } result = parts.join(decimal) end result end end |
.compile_templates(format_hash, subunit) ⇒ Object
Build each sign template with subunit precision baked in, returning a
frozen Hash of templates keyed by sign (:positive, :negative, :zero).
Keeps %
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/minting/money/format/formatting.rb', line 14 def self.compile_templates(format_hash, subunit) [ format_hash[:positive] || DEFAULT_FORMAT, format_hash[:negative], format_hash[:zero] ].map do |sign_format| next unless sign_format # Injects the currency's subunit precision into %<amount>f specifiers # (e.g. '%<amount>f' → '%<amount>.2f' for USD), preserving any # existing width/alignment specifier (e.g. '%<amount>+10f' stays). sign_format = sign_format.gsub(/%<amount>(\s*\+?\d*)f/, "%<amount>\\1.#{subunit}f") # For zero-subunit currencies (JPY, KRW, etc.), strip %<fractional>d # specifiers entirely since there is no fractional part to display. sign_format.gsub!(/%<fractional>[^%]*?d/, '') if subunit.zero? sign_format end end |
.compiled_formatters ⇒ Object
6 7 8 |
# File 'lib/minting/money/format/formatting.rb', line 6 def self.compiled_formatters @compiled_formatters ||= {} end |
.from(amount, currency) ⇒ Money
Creates a new Money immutable object with the specified amount and currency
14 15 16 17 18 19 20 21 |
# File 'lib/minting/money/constructors.rb', line 14 def self.from(amount, currency) raise ArgumentError, 'amount must be Numeric' unless amount.is_a?(Numeric) currency = Currency.resolve!(currency) amount = currency.normalize_amount(amount) amount.zero? ? currency.zero : new(amount, currency) end |
.from_subunits(subunits, currency) ⇒ Money
Builds a Money from a subunit (smallest-unit) Integer amount. This is the inverse of #subunits: for USD, the subunit is 1 cent; for JPY it is 1 yen; for IQD it is 1 dinar (subunit 3).
86 87 88 89 90 91 92 |
# File 'lib/minting/money/constructors.rb', line 86 def self.from_subunits(subunits, currency) raise ArgumentError, 'subunits must be an Integer' unless subunits.is_a?(Integer) currency = Currency.resolve!(currency) amount = Rational(subunits, currency.fractional_multiplier) amount.zero? ? currency.zero : new(amount, currency) end |
.no_currency(amount) ⇒ Money
Creates a new Money without a currency (ISO 4217 XXX — "No Currency").
30 |
# File 'lib/minting/money/constructors.rb', line 30 def self.no_currency(amount) = from(amount, 'XXX') |
.parse(input, currency = nil) ⇒ Money?
Parses a human-readable money string into a Mint::Money object.
Returns nil when the input is invalid or currency cannot be determined.
47 |
# File 'lib/minting/money/constructors.rb', line 47 def self.parse(input, currency = nil) = Mint.parse(input, currency) |
Instance Method Details
#*(multiplicand) ⇒ Money
Performs multiplication of the monetary value by a standard scalar Numeric.
42 43 44 45 46 |
# File 'lib/minting/money/arithmetics/operators.rb', line 42 def *(multiplicand) raise TypeError, "#{self} can't be multiplied by #{multiplicand}" unless multiplicand.is_a?(Numeric) copy_with(amount: amount * multiplicand) end |
#**(exponent) ⇒ Money
Performs exponentiation of the monetary value by a standard scalar Numeric.
67 68 69 70 71 |
# File 'lib/minting/money/arithmetics/operators.rb', line 67 def **(exponent) return copy_with(amount: amount**exponent) if exponent.is_a?(Numeric) raise TypeError, "#{self} can't be powered by #{exponent}" end |
#+(addend) ⇒ Money
Performs addition with another Mint::Money instance or standard zero Numeric.
11 12 13 14 15 16 17 |
# File 'lib/minting/money/arithmetics/operators.rb', line 11 def +(addend) case addend in 0 then self in Money if same_currency?(addend) then copy_with(amount: amount + addend.amount) else raise TypeError, "#{addend} can't be added to #{self}" end end |
#-(subtrahend) ⇒ Money
Performs subtraction with another Mint::Money instance or standard zero Numeric.
24 25 26 27 28 29 30 |
# File 'lib/minting/money/arithmetics/operators.rb', line 24 def -(subtrahend) case subtrahend when 0 then return self when Money then return copy_with(amount: amount - subtrahend.amount) if same_currency?(subtrahend) end raise TypeError, "#{subtrahend} can't be subtracted from #{self}" end |
#-@ ⇒ Money
Unary negation operator. Returns a new Mint::Money instance with the inverted sign.
35 |
# File 'lib/minting/money/arithmetics/operators.rb', line 35 def -@ = copy_with(amount: -amount) |
#/(divisor) ⇒ Money, Numeric
Performs division of the monetary value by a scalar Numeric or identical currency Mint::Money.
54 55 56 57 58 59 60 |
# File 'lib/minting/money/arithmetics/operators.rb', line 54 def /(divisor) case divisor when Numeric then return copy_with(amount: amount / divisor) when Money then return amount / divisor.amount if same_currency? divisor end raise TypeError, "#{self} can't be divided by #{divisor}" end |
#<=>(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 40 41 42 |
# File 'lib/minting/money/comparable.rb', line 36 def <=>(other) case other in 0 then amount <=> other in Mint::Money if same_currency?(other) then amount <=> other.amount else raise TypeError, "#{inspect} can't be compared to #{other.inspect}" end end |
#==(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if both are zero, or both have same amount and same currency.
9 10 11 12 13 14 15 |
# File 'lib/minting/money/comparable.rb', line 9 def ==(other) case other when 0 then zero? when Mint::Money then amount == other.amount && currency == other.currency else false end end |
#abs ⇒ Money
Returns the absolute value of the monetary amount as a new Mint::Money instance.
9 |
# File 'lib/minting/money/arithmetics/methods.rb', line 9 def abs = copy_with(amount: amount.abs) |
#allocate(proportions) ⇒ Array<Money>
Proportionally allocates the monetary amount among a list of ratios. Disperses any subunit rounding amounts across the initial slots
15 16 17 18 19 20 21 22 |
# File 'lib/minting/money/allocation/allocation.rb', line 15 def allocate(proportions) whole = proportions.sum.to_r raise ArgumentError, 'Need at least 1 proportion element' if proportions.empty? raise ArgumentError, 'Proportions total must not be zero' if whole.zero? amounts = proportions.map { |rate| currency.normalize_amount(Rational(amount * rate, whole)) } allocate_left_over(amounts: amounts, left_over: amount - amounts.sum) end |
#clamp(min_or_range, max = nil) ⇒ Money
Constrains self to the inclusive range [+min+, +max+].
Bounds may be:
- nil meaning no boundary
- same-currency Mint::Money or Range
- Numeric amount, or Range
Numeric is interpreted as an amount in +self+'s currency, so the common
pricing idiom price.clamp(0, 100) reads as "0 to 100 in the same
currency as +price+".
When self is already in range the receiver is returned (no new object
allocated). When out of range, the nearest bound is returned as a new
frozen Mint::Money in +self+'s currency.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/minting/money/clamp.rb', line 42 def clamp(min_or_range, max = nil) if min_or_range.is_a?(Range) raise(ArgumentError, "Either amount range alone or two amounts accepted: #{max}") if max min, max = min_or_range.minmax else min = min_or_range end copy_with(amount: amount.clamp(normalize_boundary(min), normalize_boundary(max))) end |
#coerce(other) ⇒ Array(CoercedNumber, Money)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Allows Mint::Money to interact seamlessly as the right-hand operand in Numeric arithmetic.
This enables expressions like 5 * money where 5 is a Numeric and money is a Money object.
14 15 16 |
# File 'lib/minting/money/coercion.rb', line 14 def coerce(other) [CoercedNumber.new(other), self] end |
#copy_with(amount:) ⇒ Money
Returns a new Money object with the specified amount, or self if unchanged. This is the primary method for creating a modified copy of a Money instance while preserving immutability.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/minting/money/constructors.rb', line 104 def copy_with(amount:) amount = currency.normalize_amount(amount) if amount == self.amount self elsif amount.zero? currency.zero else Money.new(amount, currency) end end |
#currency_code ⇒ String
Returns the ISO 3-letter currency code string.
27 |
# File 'lib/minting/money/money.rb', line 27 def currency_code = currency.code |
#eql?(other) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Strict equality — both amount and currency must match exactly. Unlike ==, does not treat zero as equivalent across currencies.
21 22 23 24 25 |
# File 'lib/minting/money/comparable.rb', line 21 def eql?(other) other.is_a?(Mint::Money) && amount == other.amount && currency == other.currency end |
#format(preset = nil, format: nil, decimal: nil, thousand: nil, width: nil) ⇒ String Also known as: to_fs
Formats money as a string with customizable format, thousand delimiter, and decimal
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/minting/money/format/to_s.rb', line 83 def format(preset = nil, format: nil, decimal: nil, thousand: nil, width: nil) if preset config = PRESETS.fetch(preset) { raise ArgumentError, "Unknown format preset: #{preset.inspect}" } format ||= config[:format] decimal ||= config[:decimal] thousand ||= config[:thousand] width ||= config[:width] end validate_separators!(decimal:, thousand:) format, decimal, thousand = resolve_locale_for(format, decimal, thousand) case format when {}, '' then raise ArgumentError, 'format must not be empty' when Hash then validate_format_hash(format) when String then format = { positive: format } else raise ArgumentError, 'Invalid format. Only String or Hash are accepted' end formatted = format_amount(format, decimal:, thousand:) width ? formatted.rjust(width) : formatted end |
#fractional ⇒ Object
Returns the fractional part of the amount.
44 |
# File 'lib/minting/money/money.rb', line 44 def fractional = ((amount.abs % 1) * currency.fractional_multiplier).to_i |
#hash ⇒ Integer
Generates a stable hash key for Money instances.
49 |
# File 'lib/minting/money/money.rb', line 49 def hash = [amount, currency_code].hash |
#inspect ⇒ String
Returns a standard developer-oriented string inspection of the Money object.
54 55 56 |
# File 'lib/minting/money/money.rb', line 54 def inspect Kernel.format "[#{currency_code} %0.#{currency.subunit}f]", amount end |
#mint(new_amount) ⇒ Money
Use #copy_with instead. Will be removed in v2.
Returns a new Money with the given amount in the same currency.
123 124 125 126 |
# File 'lib/minting/money/constructors.rb', line 123 def mint(new_amount) warn 'Money#mint is now deprecated and will be removed in v2' copy_with(amount: new_amount) end |
#negative? ⇒ Boolean
Returns true if the monetary amount is less than zero.
14 |
# File 'lib/minting/money/arithmetics/methods.rb', line 14 def negative? = amount.negative? |
#nonzero? ⇒ self?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns self if amount is non-zero, nil otherwise.
45 |
# File 'lib/minting/money/comparable.rb', line 45 def nonzero? = amount.nonzero? |
#positive? ⇒ Boolean
Returns true if the monetary amount is greater than zero.
19 |
# File 'lib/minting/money/arithmetics/methods.rb', line 19 def positive? = amount.positive? |
#same_currency?(other) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Helper method to verify if another Money has the identical currency.
51 |
# File 'lib/minting/money/comparable.rb', line 51 def same_currency?(other) = other.currency == currency |
#split(slices) ⇒ Array<Money>
Splits the monetary amount into a given quantity of equal parts. Disperses any fractional subunit rounding differences across the initial slots so that the sum is preserved.
17 18 19 20 21 22 23 |
# File 'lib/minting/money/allocation/split.rb', line 17 def split(slices) raise ArgumentError, 'Slices quantity must be an poitive integer' unless slices.positive? && slices.integer? fraction = currency.normalize_amount(amount / slices) allocate_left_over(amounts: Array.new(slices, fraction), left_over: amount - (fraction * slices)) end |
#subunits ⇒ Integer
Returns the monetary amount expressed in the currency's smallest unit (fractional units). For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (subunit 3).
37 |
# File 'lib/minting/money/money.rb', line 37 def subunits = (amount * currency.fractional_multiplier).to_i |
#succ ⇒ Money
Returns the successor of the Money instance by adding the minimum possible subunit amount.
Enables standard ranges and stepping (e.g. 1.dollar..10.dollars).
25 |
# File 'lib/minting/money/arithmetics/methods.rb', line 25 def succ = copy_with(amount: amount + currency.minimum_amount) |
#to_d ⇒ BigDecimal
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the monetary amount to a BigDecimal object.
15 |
# File 'lib/minting/money/conversion.rb', line 15 def to_d = amount.to_d 0 |
#to_f ⇒ Float
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the monetary amount to a standard float. Note: Using float conversion loses precision guarantees.
21 |
# File 'lib/minting/money/conversion.rb', line 21 def to_f = amount.to_f |
#to_hash ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a Hash representation of the money instance.
48 49 50 |
# File 'lib/minting/money/conversion.rb', line 48 def to_hash { currency: currency_code, amount: Kernel.format("%0.#{currency.subunit}f", amount) } end |
#to_html(format = DEFAULT_FORMAT) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Renders a safe HTML5 <data> element containing the formatted currency.
Embeds the ISO currency description and raw value as the metadata title attribute.
28 29 30 31 32 |
# File 'lib/minting/money/conversion.rb', line 28 def to_html(format = DEFAULT_FORMAT) title = Kernel.format("#{currency_code} %0.#{currency.subunit}f", amount) body = format(format: format) %(<data class='money' title='#{title}'>#{ERB::Util.html_escape(body)}</data>) end |
#to_i ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Truncates and converts the monetary amount to an Integer.
40 |
# File 'lib/minting/money/conversion.rb', line 40 def to_i = amount.to_i |
#to_json(*_args) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serializes the money instance to a standard JSON object containing the amount and currency. Highly optimized to run without external dependencies.
56 57 58 59 60 |
# File 'lib/minting/money/conversion.rb', line 56 def to_json(*_args) Kernel.format( %({"currency": "#{currency_code}", "amount": "%0.#{currency.subunit}f"}), amount ) end |
#to_r ⇒ Rational
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the exact internal Rational representation of the monetary amount.
65 |
# File 'lib/minting/money/conversion.rb', line 65 def to_r = amount |
#to_s ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/minting/money/format/to_s.rb', line 110 def to_s return format unless Mint.locale_backend.nil? subunit = currency.subunit integral = to_i.to_s integral.gsub!(THOUSAND_RE, '\1,') if amount.abs >= 1000 if subunit > 0 "#{currency.symbol}#{integral}.#{fractional.to_s.rjust(subunit, '0')}" else "#{currency.symbol}#{integral}" end end |
#zero? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if amount is zero.
54 |
# File 'lib/minting/money/comparable.rb', line 54 def zero? = amount.zero? |