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.
233 234 235 236 237 |
# File 'lib/money/money/formatter.rb', line 233 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
254 255 256 |
# File 'lib/money/money/formatter.rb', line 254 def decimal_mark lookup :decimal_mark end |
#thousands_separator ⇒ Object Also known as: delimiter
246 247 248 249 250 251 252 |
# File 'lib/money/money/formatter.rb', line 246 def thousands_separator val = lookup :thousands_separator return val unless val == true lookup_default :thousands_separator end |
#to_s ⇒ Object
239 240 241 242 243 244 |
# File 'lib/money/money/formatter.rb', line 239 def to_s return free_text if show_free_text? result = format_number formatted = append_sign(result) append_currency_symbol(formatted) end |