Class: Money::Formatter
- Inherits:
-
Object
- Object
- Money::Formatter
- Defined in:
- lib/money/money/formatter.rb
Constant Summary collapse
- DEFAULTS =
{ thousands_separator: '', decimal_mark: '.' }.freeze
Instance Method Summary collapse
- #decimal_mark ⇒ Object (also: #separator)
-
#initialize(money, *rules) ⇒ String
constructor
Creates a formatted price string according to several rules.
- #thousands_separator ⇒ Object (also: #delimiter)
- #to_s ⇒ Object
Constructor Details
#initialize(money, *rules) ⇒ String
Creates a formatted price string according to several rules.
with the symbol (if present) and %n will be replaced with the number.
Note that the default rules can be defined through Money.default_formatting_rules hash.
186 187 188 189 190 |
# File 'lib/money/money/formatter.rb', line 186 def initialize(money, *rules) @money = money @currency = money.currency @rules = FormattingRules.new(@currency, *rules) end |
Instance Method Details
#decimal_mark ⇒ Object Also known as: separator
207 208 209 |
# File 'lib/money/money/formatter.rb', line 207 def decimal_mark lookup :decimal_mark end |
#thousands_separator ⇒ Object Also known as: delimiter
199 200 201 202 203 204 205 |
# File 'lib/money/money/formatter.rb', line 199 def thousands_separator val = lookup :thousands_separator return val unless val == true lookup_default :thousands_separator end |
#to_s ⇒ Object
192 193 194 195 196 197 |
# File 'lib/money/money/formatter.rb', line 192 def to_s return free_text if show_free_text? result = format_number formatted = append_sign(result) append_currency_symbol(formatted) end |