Class: Ronin::Core::Params::Types::Boolean

Inherits:
Type
  • Object
show all
Defined in:
lib/ronin/core/params/types/boolean.rb

Overview

Represents a true/false param.

Instance Method Summary collapse

Instance Method Details

#coerce(value) ⇒ true, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerces a value into a boolean value.

Parameters:

  • value (::String, true, false, nil)

    The value to coerce.

Returns:

  • (true, false, nil)

    The coerced boolean value.

Raises:

  • (ValidationError)

    The given value was not nil, true, false, "true", "false", "yes", "no", "y", "n", "on", or "off".



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ronin/core/params/types/boolean.rb', line 44

def coerce(value)
  case value
  when nil         then false
  when true, false then value
  when ::String
    case value
    when /\A(?:true|yes|y|on)\z/i  then true
    when /\A(?:false|no|n|off)\z/i then false
    else
      raise(ValidationError,"value must be either 'true', 'false', 'yes', 'no', 'y', 'n', 'on', or 'off' (#{value.inspect})")
    end
  else
    raise(ValidationError,"value must be either true, false, or a String (#{value.inspect})")
  end
end