Sha256: d6fb57964d206b1c5b046f4ae30ddf928b22bd98945adb1fc0d590e61ee818bd

Contents?: true

Size: 395 Bytes

Versions: 5

Compression:

Stored size: 395 Bytes

Contents

module InputSanitizer
  class CommaJoinedStringsConverter
    def call(value)
      value = value.to_s
      non_valid = value.gsub(/[a-zA-Z,_]/, "")

      if non_valid.empty?
        value.split(",").map(&:to_s)
      else
        invalid_chars = non_valid.split(//).join(", ")
        raise InputSanitizer::ConversionError.new("Invalid strings: #{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_strings_converter.rb
input_sanitizer-0.5.0 lib/input_sanitizer/extended_converters/comma_joined_strings_converter.rb
input_sanitizer-0.4.1 lib/input_sanitizer/extended_converters/comma_joined_strings_converter.rb
input_sanitizer-0.4.0 lib/input_sanitizer/extended_converters/comma_joined_strings_converter.rb
input_sanitizer-0.3.33 lib/input_sanitizer/extended_converters/comma_joined_strings_converter.rb