Class: StoreSchema::Converter::Boolean
- Defined in:
- lib/store_schema/converter/boolean.rb
Constant Summary collapse
- DB_TRUE_VALUE =
Returns the database representation of a true value.
"t"
- DB_FALSE_VALUE =
Returns the database representation of a false value.
"f"
- TRUE_VALUES =
Returns all the values that are considered to be truthy.
[true, 1, "1", "t", "T", "true", "TRUE", "on", "ON"]
- FALSE_VALUES =
Returns all the values that are considered to be falsy.
[false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"]
Instance Attribute Summary collapse
- #value ⇒ Object readonly
Instance Method Summary collapse
-
#from_db ⇒ true, false
Converts the #value to a Ruby-type value.
-
#initialize(value) ⇒ Boolean
constructor
A new instance of Boolean.
-
#to_db ⇒ String, false
Converts the #value to a database-storable value.
Constructor Details
#initialize(value) ⇒ Boolean
Returns a new instance of Boolean.
27 28 29 |
# File 'lib/store_schema/converter/boolean.rb', line 27 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
23 24 25 |
# File 'lib/store_schema/converter/boolean.rb', line 23 def value @value end |
Instance Method Details
#from_db ⇒ true, false
Converts the #value to a Ruby-type value.
49 50 51 |
# File 'lib/store_schema/converter/boolean.rb', line 49 def from_db value == DB_TRUE_VALUE end |
#to_db ⇒ String, false
Converts the #value to a database-storable value.
35 36 37 38 39 40 41 42 43 |
# File 'lib/store_schema/converter/boolean.rb', line 35 def to_db if TRUE_VALUES.include?(value) DB_TRUE_VALUE elsif FALSE_VALUES.include?(value) DB_FALSE_VALUE else false end end |