Class: ActiveSupport::NumberHelper::NumberToHumanConverter
- Inherits:
-
NumberConverter
- Object
- NumberConverter
- ActiveSupport::NumberHelper::NumberToHumanConverter
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/number_helper/number_to_human_converter.rb
Overview
:nodoc:
Constant Summary collapse
- DECIMAL_UNITS =
{ 0 => :unit, 1 => :ten, 2 => :hundred, 3 => :thousand, 6 => :million, 9 => :billion, 12 => :trillion, 15 => :quadrillion, -1 => :deci, -2 => :centi, -3 => :mili, -6 => :micro, -9 => :nano, -12 => :pico, -15 => :femto }
- INVERTED_DECIMAL_UNITS =
DECIMAL_UNITS.invert
Constants inherited from NumberConverter
ActiveSupport::NumberHelper::NumberConverter::DEFAULTS
Instance Attribute Summary
Attributes inherited from NumberConverter
Instance Method Summary collapse
-
#convert ⇒ Object
:nodoc:.
Methods inherited from NumberConverter
convert, #execute, #initialize
Constructor Details
This class inherits a constructor from ActiveSupport::NumberHelper::NumberConverter
Instance Method Details
#convert ⇒ Object
:nodoc:
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/number_helper/number_to_human_converter.rb', line 15 def convert # :nodoc: @number = RoundingHelper.new().round(number) @number = Float(number) # For backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files. unless .key?(:strip_insignificant_zeros) [:strip_insignificant_zeros] = true end units = opts[:units] exponent = calculate_exponent(units) @number = number / (10**exponent) rounded_number = NumberToRoundedConverter.convert(number, ) unit = determine_unit(units, exponent) format.gsub("%n", rounded_number).gsub("%u", unit).strip end |