Sha256: 6222d0cea1d0b1bee3ac6492b543091bc42c193d16fec4d1cb042c689328bcbb

Contents?: true

Size: 479 Bytes

Versions: 5

Compression:

Stored size: 479 Bytes

Contents

module InputSanitizer
  class SpecificValuesConverter
    def initialize(values)
      @valid_values = values
    end

    def call(value)
      case
      when @valid_values.include?(value)
        value
      when value.respond_to?(:to_sym) && @valid_values.include?(value.to_sym)
        value.to_sym
      else
        values_joined = @valid_values.join(", ")
        raise InputSanitizer::ConversionError.new("Possible values: #{values_joined}")
      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/specific_values_converter.rb
input_sanitizer-0.5.0 lib/input_sanitizer/extended_converters/specific_values_converter.rb
input_sanitizer-0.4.1 lib/input_sanitizer/extended_converters/specific_values_converter.rb
input_sanitizer-0.4.0 lib/input_sanitizer/extended_converters/specific_values_converter.rb
input_sanitizer-0.3.33 lib/input_sanitizer/extended_converters/specific_values_converter.rb