class TTY::Prompt::Question::Validation

A class representing question validation.

def call(input)

Other tags:
    Api: - public

Returns:
  • (Boolean) -

Parameters:
  • input (Object) --
def call(input)
  if pattern.is_a?(String) || pattern.is_a?(Symbol)
    VALIDATORS.key?(pattern.to_sym)
    !VALIDATORS[pattern.to_sym].match(input.to_s).nil?
  elsif pattern.is_a?(Regexp)
    !pattern.match(input.to_s).nil?
  elsif pattern.is_a?(Proc)
    result = pattern.call(input.to_s)
    result.nil? ? false : result
  else false
  end
end

def coerce(pattern)

Other tags:
    Api: - private

Raises:
  • (TTY::ValidationCoercion) -

Parameters:
  • pattern (Object) --
def coerce(pattern)
  case pattern
  when String, Symbol, Proc
    pattern
  when Regexp
    Regexp.new(pattern.to_s)
  else
    raise ValidationCoercion, "Wrong type, got #{pattern.class}"
  end
end

def initialize(pattern)

Other tags:
    Api: - private

Returns:
  • (undefined) -

Parameters:
  • pattern (Object) --
def initialize(pattern)
  @pattern = coerce(pattern)
end