Sha256: a32677fee717b440baa099d38e0fd4122a891c1d8ade8cdea47566d640f841d9

Contents?: true

Size: 393 Bytes

Versions: 5

Compression:

Stored size: 393 Bytes

Contents

module InputSanitizer
  class CommaJoinedIntegersConverter
    def call(value)
      value = value.to_s
      non_valid = value.gsub(/[0-9,]/, "")

      if non_valid.empty?
        value.split(",").map(&:to_i)
      else
        invalid_chars = non_valid.split(//).join(", ")
        raise InputSanitizer::ConversionError.new("Invalid integers: #{invalid_chars}")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
input_sanitizer-0.6.0 lib/input_sanitizer/extended_converters/comma_joined_integers_converter.rb
input_sanitizer-0.5.0 lib/input_sanitizer/extended_converters/comma_joined_integers_converter.rb
input_sanitizer-0.4.1 lib/input_sanitizer/extended_converters/comma_joined_integers_converter.rb
input_sanitizer-0.4.0 lib/input_sanitizer/extended_converters/comma_joined_integers_converter.rb
input_sanitizer-0.3.33 lib/input_sanitizer/extended_converters/comma_joined_integers_converter.rb