Class: StoreSchema::Converter::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/store_schema/converter/boolean.rb

Constant Summary collapse

DB_TRUE_VALUE =

Returns the database representation of a true value.

Returns:

  • (String)

    the database representation of a true value.

"t"
DB_FALSE_VALUE =

Returns the database representation of a false value.

Returns:

  • (String)

    the database representation of a false value.

"f"
TRUE_VALUES =

Returns all the values that are considered to be truthy.

Returns:

  • (Array)

    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.

Returns:

  • (Array)

    all the values that are considered to be falsy.

[false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Boolean

Returns a new instance of Boolean.

Parameters:

  • value (Object)

27
28
29
# File 'lib/store_schema/converter/boolean.rb', line 27

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns:

  • (Object)

23
24
25
# File 'lib/store_schema/converter/boolean.rb', line 23

def value
  @value
end

Instance Method Details

#from_dbtrue, false

Converts the #value to a Ruby-type value.

Returns:

  • (true, false)

49
50
51
# File 'lib/store_schema/converter/boolean.rb', line 49

def from_db
  value == DB_TRUE_VALUE
end

#to_dbString, false

Converts the #value to a database-storable value.

Returns:

  • (String, false)

    false if #value is an invalid date-type.


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