Class: Clive::Type::Boolean

Inherits:
Object show all
Defined in:
lib/clive/type/definitions.rb

Overview

Boolean will accept 'true', 't', 'yes', 'y' or 'on' as true and 'false', 'f', 'no', 'n' or 'off' as false.

Constant Summary collapse

TRUE_VALUES =
%w(true t yes y on)
FALSE_VALUES =
%w(false f no n off)

Instance Method Summary collapse

Methods inherited from Clive::Type

cast, find_class, match, refute, typecast, valid?

Instance Method Details

#typecast(arg) ⇒ Object


92
93
94
95
96
97
# File 'lib/clive/type/definitions.rb', line 92

def typecast(arg)
  case arg
    when *TRUE_VALUES  then true
    when *FALSE_VALUES then false
  end
end

#valid?(arg) ⇒ Boolean

Returns:


88
89
90
# File 'lib/clive/type/definitions.rb', line 88

def valid?(arg)
  (TRUE_VALUES + FALSE_VALUES).include? arg
end