Class: Goliath::Rack::Types::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/goliath/rack/types/boolean.rb

Constant Summary collapse

TRUE_STRINGS =
['true', 't', '1']
FALSE_STRINGS =
['false', 'f', '0']
ERROR_MESSAGE =
"%s is not a boolean value"

Instance Method Summary collapse

Methods inherited from Base

#coerce, #initialize

Methods included from Validator

safely, validation_error

Constructor Details

This class inherits a constructor from Goliath::Rack::Types::Base

Instance Method Details

#_coerce(val) ⇒ Object



9
10
11
12
13
14
# File 'lib/goliath/rack/types/boolean.rb', line 9

def _coerce(val)
  downcased_val = val.downcase
  return true if TRUE_STRINGS.include?(downcased_val)
  return false if FALSE_STRINGS.include?(downcased_val)
  raise ERROR_MESSAGE % val
end