Sha256: fba4d43070e6df46ab3dd8beaf49857e9234ff39de72042da1ff46fb30725288

Contents?: true

Size: 693 Bytes

Versions: 49

Compression:

Stored size: 693 Bytes

Contents

# frozen_string_literal: true

module ActiveSupport
  module NumberHelper
    class NumberToDelimitedConverter < NumberConverter #:nodoc:
      self.validate_float = true

      DEFAULT_DELIMITER_REGEX = /(\d)(?=(\d\d\d)+(?!\d))/

      def convert
        parts.join(options[:separator])
      end

      private

        def parts
          left, right = number.to_s.split(".".freeze)
          left.gsub!(delimiter_pattern) do |digit_to_delimit|
            "#{digit_to_delimit}#{options[:delimiter]}"
          end
          [left, right].compact
        end

        def delimiter_pattern
          options.fetch(:delimiter_pattern, DEFAULT_DELIMITER_REGEX)
        end
    end
  end
end

Version data entries

49 entries across 49 versions & 8 rubygems

Version Path
activesupport-5.2.8.1 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.8 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.7.1 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.7 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.6.3 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.6.2 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.6.1 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.6 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.4.6 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.5 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.4.5 lib/active_support/number_helper/number_to_delimited_converter.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.4.4 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.4.3 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.4.2 lib/active_support/number_helper/number_to_delimited_converter.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.4.1/lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.4.1 lib/active_support/number_helper/number_to_delimited_converter.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.4 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.2.4.rc1 lib/active_support/number_helper/number_to_delimited_converter.rb