Class: Momomoto::Datatype::Boolean
- Defined in:
- lib/momomoto/datatype/boolean.rb
Overview
This class represents values of boolean type.
Instance Method Summary collapse
-
#escape(input) ⇒ Object
Converts the given
input
to true or false if possible. -
#filter_set(value) ⇒ Object
Values are filtered by this method when being set.
Methods inherited from Base
#compile_rule, #default, #default_operator, #equal, #initialize, #not_null?, operator_sign
Constructor Details
This class inherits a constructor from Momomoto::Datatype::Base
Instance Method Details
#escape(input) ⇒ Object
Converts the given input
to true or false if possible. Otherwise returns NULL.
22 23 24 25 26 27 28 |
# File 'lib/momomoto/datatype/boolean.rb', line 22 def escape( input ) case input when true, 1, 't', 'true', 'on' then "'t'" when false, 0, 'f', 'false', 'off' then "'f'" else "NULL" end end |
#filter_set(value) ⇒ Object
Values are filtered by this method when being set. Returns true or false. If the given value
cannot be converted to true or false and NULL is not allowed, than again return false. Otherwise return nil
.
12 13 14 15 16 17 18 |
# File 'lib/momomoto/datatype/boolean.rb', line 12 def filter_set( value ) case value when true, 1, 't', 'true', 'on' then true when false, 0, 'f', 'false', 'off' then false else not_null? ? false : nil end end |