Class: Db2Query::Type::Boolean

Inherits:
Value
  • Object
show all
Defined in:
lib/db2_query/type/boolean.rb

Constant Summary collapse

TRUE_VALUES =
[
  true, 1, "1", "t", "T",
  "true", "TRUE", "on", "ON",
  :"1", :t, :T, :true, :TRUE, :on, :ON
].freeze
DEFAULT =
{ true: true, false: false }

Instance Attribute Summary

Attributes inherited from Value

#options

Instance Method Summary collapse

Methods inherited from Value

#quote, #type_name

Constructor Details

#initialize(options = DEFAULT) ⇒ Boolean

Returns a new instance of Boolean.



14
15
16
# File 'lib/db2_query/type/boolean.rb', line 14

def initialize(options = DEFAULT)
  super(options)
end

Instance Method Details

#deserialize(value) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/db2_query/type/boolean.rb', line 31

def deserialize(value)
  case value
  when 1
    options[:true]
  else
    options[:false]
  end
end

#nameObject



18
19
20
# File 'lib/db2_query/type/boolean.rb', line 18

def name
  :boolean
end

#serialize(value) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/db2_query/type/boolean.rb', line 22

def serialize(value)
  case value
  when *TRUE_VALUES
    1
  else
    0
  end
end