Module: Ascribe::Extensions::Boolean

Included in:
Boolean
Defined in:
lib/ascribe/extensions/boolean.rb

Constant Summary collapse

Mapping =
{
  true    => true, 
  'true'  => true, 
  'TRUE'  => true, 
  'True'  => true, 
  't'     => true, 
  'T'     => true, 
  '1'     => true, 
  1       => true, 
  1.0     => true,
  false   => false, 
  'false' => false, 
  'FALSE' => false, 
  'False' => false, 
  'f'     => false, 
  'F'     => false, 
  '0'     => false, 
  0       => false, 
  0.0     => false, 
  nil     => nil
}

Instance Method Summary collapse

Instance Method Details

#from_store(value) ⇒ Object



34
35
36
# File 'lib/ascribe/extensions/boolean.rb', line 34

def from_store(value, *)
  value.nil? ? nil : !!value
end

#to_store(value) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ascribe/extensions/boolean.rb', line 26

def to_store(value, *)
  if value.is_a?(Boolean)
    value
  else
    Mapping[value]
  end
end