Module: LucidWorks::Utils::BoolConverter

Included in:
Base
Defined in:
lib/lucid_works/utils.rb

Constant Summary collapse

TRUE_VALUES =
%w(t true  1 yes)
FALSE_VALUES =
%w(f false 0 no)

Instance Method Summary collapse

Instance Method Details

#to_bool(thing) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/lucid_works/utils.rb', line 7

def to_bool(thing)
  if thing.kind_of?(TrueClass) || thing.kind_of?(FalseClass)
    thing
  elsif thing.kind_of?(String)
    raise "Sorry, I can't to_bool \"#{thing}\"" unless (TRUE_VALUES + FALSE_VALUES).include?(thing.downcase)
    TRUE_VALUES.include?(thing.downcase)
  elsif thing.kind_of?(Integer)
    raise "Sorry, I can't to_bool #{thing}" unless [0, 1].include?(thing)
    thing == 1
  else
    raise "Sorry, I can't to_bool things of class #{thing.class.name}"
  end
end