Class: ActiveSupport::NumberHelper::NumberToHumanSizeConverter

Inherits:
NumberConverter show all
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_size_converter.rb

Overview

:nodoc:

Constant Summary collapse

STORAGE_UNITS =
[:byte, :kb, :mb, :gb, :tb, :pb, :eb]

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/number_helper/number_to_human_size_converter.rb', line 13

def convert
  @number = Float(number)

  # For backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files.
  unless options.key?(:strip_insignificant_zeros)
    options[:strip_insignificant_zeros] = true
  end

  if smaller_than_base?
    number_to_format = number.to_i.to_s
  else
    human_size = number / (base**exponent)
    number_to_format = NumberToRoundedConverter.convert(human_size, options)
  end
  conversion_format.gsub("%n", number_to_format).gsub("%u", unit)
end