Class: ActiveSupport::NumberHelper::NumberToCurrencyConverter

Inherits:
NumberConverter show all
Defined in:
lib/active_support/number_helper/number_to_currency_converter.rb

Overview

:nodoc:

Constant Summary

Constants inherited from NumberConverter

ActiveSupport::NumberHelper::NumberConverter::DEFAULTS

Instance Attribute Summary

Attributes inherited from NumberConverter

#number, #opts

Instance Method Summary collapse

Methods inherited from NumberConverter

convert, #execute, #initialize

Constructor Details

This class inherits a constructor from ActiveSupport::NumberHelper::NumberConverter

Instance Method Details

#convertObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/active_support/number_helper/number_to_currency_converter.rb', line 8

def convert
  number = self.number.to_s.strip
  format = options[:format]

  if number.to_f.negative?
    format = options[:negative_format]
    number = absolute_value(number)
  end

  rounded_number = NumberToRoundedConverter.convert(number, options)
  format.gsub("%n".freeze, rounded_number).gsub("%u".freeze, options[:unit])
end