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)


29
30
31
# File 'lib/store_schema/converter/boolean.rb', line 29

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns:

  • (Object)


25
26
27
# File 'lib/store_schema/converter/boolean.rb', line 25

def value
  @value
end

Instance Method Details

#from_dbtrue, false

Converts the #value to a Ruby-type value.

Returns:

  • (true, false)


51
52
53
# File 'lib/store_schema/converter/boolean.rb', line 51

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.



37
38
39
40
41
42
43
44
45
# File 'lib/store_schema/converter/boolean.rb', line 37

def to_db
  if TRUE_VALUES.include?(value)
    DB_TRUE_VALUE
  elsif FALSE_VALUES.include?(value)
    DB_FALSE_VALUE
  else
    false
  end
end