Sha256: 435f22af038cbf86177e972655d39a734f6934e22a9c9c616d3219d5f8446049

Contents?: true

Size: 475 Bytes

Versions: 11

Compression:

Stored size: 475 Bytes

Contents

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

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

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

      private

        def parts
          left, right = number.to_s.split('.')
          left.gsub!(DELIMITED_REGEX) { "#{$1}#{options[:delimiter]}" }
          [left, right].compact
        end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
whos_dated_who-0.1.0 vendor/bundle/gems/activesupport-4.1.1/lib/active_support/number_helper/number_to_delimited_converter.rb
whos_dated_who-0.0.1 vendor/bundle/gems/activesupport-4.1.1/lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-4.1.1 lib/active_support/number_helper/number_to_delimited_converter.rb
elch_scan-0.1.2 lib/active_support/number_helper/number_to_delimited_converter.rb
elch_scan-0.1.1 lib/active_support/number_helper/number_to_delimited_converter.rb
elch_scan-0.1.0 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-4.1.0 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-4.1.0.rc2 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-4.1.0.rc1 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-4.1.0.beta2 lib/active_support/number_helper/number_to_delimited_converter.rb
activesupport-4.1.0.beta1 lib/active_support/number_helper/number_to_delimited_converter.rb