Class: CodeKindly::Utils::Boolean

Inherits:
Object
  • Object
show all
Defined in:
lib/code_kindly/utils/boolean.rb

Constant Summary collapse

TRUE_VALUES =

modified from ActiveRecord::ConnectionAdapters::Column (4.2.9)

[true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON', 'y', 'yes']
FALSE_VALUES =
[false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF', 'n', 'no']

Class Method Summary collapse

Class Method Details

.from(value) ⇒ Object



9
10
11
12
13
# File 'lib/code_kindly/utils/boolean.rb', line 9

def from (value)
  return true  if is_true?(value)
  return false if is_false?(value)
  nil
end

.is_false?(value) ⇒ Boolean

Returns:



15
16
17
18
19
20
21
# File 'lib/code_kindly/utils/boolean.rb', line 15

def is_false? (value)
  return true if FALSE_VALUES.include?(value)
  if value.respond_to?(:downcase)
    return true if FALSE_VALUES.include?(value.downcase)
  end
  false
end

.is_true?(value) ⇒ Boolean

Returns:



23
24
25
26
27
28
29
# File 'lib/code_kindly/utils/boolean.rb', line 23

def is_true? (value)
  return true if TRUE_VALUES.include?(value)
  if value.respond_to?(:downcase)
    return true if TRUE_VALUES.include?(value.downcase)
  end
  false
end