class Necromancer::RangeConverters::StringToRangeConverter

An object that converts a String to a Range

Public Instance Methods

call(value, options = {}) click to toggle source

Convert value to Range type with possible ranges

@param [Object] value

@example

converter.call('0,9')  # => (0..9)

@example

converter.call('0-9')  # => (0..9)

@api public

# File lib/necromancer/converters/range.rb, line 27
def call(value, options = {})
  strict = options.fetch(:strict, config.strict)
  case value
  when SINGLE_DIGIT_MATCHER
    ::Range.new($1.to_i, $1.to_i)
  when DIGIT_MATCHER
    ::Range.new($1.to_i, $3.to_i, $2 == '...')
  when LETTER_MATCHER
    ::Range.new($1.to_s, $3.to_s, $2 == '...')
  else
    strict ? fail_conversion_type(value) : value
  end
end