Sha256: eb07aef110334e50900cbafc19c6b897096d0f8a028276c11af0eb6b7b8eb43c

Contents?: true

Size: 662 Bytes

Versions: 23

Compression:

Stored size: 662 Bytes

Contents

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

23 entries across 23 versions & 3 rubygems

Version Path
activesupport-5.1.7 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.7.rc1 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.6.2 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.6.1 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.6 lib/active_support/number_helper/number_to_delimited_converter.rb
tdiary-5.0.8 vendor/bundle/gems/activesupport-5.1.5/lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.5 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.5.rc1 lib/active_support/number_helper/number_to_delimited_converter.rb
pract6-0.1.0 .gem/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.4 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.4.rc1 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.3 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.3.rc3 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.3.rc2 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.3.rc1 lib/active_support/number_helper/number_to_delimited_converter.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.1.2/lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.2 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.2.rc1 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.1 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-5.1.0 lib/active_support/number_helper/number_to_delimited_converter.rb