module Utilise::Augment::Bool

Extends classes that could be treated as a boolean

Public Instance Methods

bool_array(array) click to toggle source

Iterates through array and updates each element to a boolean if it matches rules

@param array [Array] the array

# File lib/utilise/augment/bool.rb, line 35
def bool_array(array)
  array.each_index do |index|
    val = to_bool(array[index])
    array[index] = val unless val.nil?
  end
end
bool_hash(hash) click to toggle source

Iterates through hash and updates each key value to a boolean if it matches rules

@param hash [Hash] the hash

# File lib/utilise/augment/bool.rb, line 24
def bool_hash(hash)
  hash.each do |key, val|
    val = to_bool(val)
    hash[key] = val unless val.nil?
  end
end
bool_it(object) click to toggle source

Returns boolean value if object matches rules

@param object [Object] object to bool @returns [Boolean] true/false returned

# File lib/utilise/augment/bool.rb, line 46
def bool_it(object)
  case object.to_s
  when /^true$/i, /^yes$/i, /^t$/i, /^1$/i
    true
  when /^false$/i, /^no$/i, /^f$/i, /^0$/i
    false
  end
end
to_bool(object = self) click to toggle source

Returns bool based on object passed

@param object [Object] the object @return [Object] returns object boolean

# File lib/utilise/augment/bool.rb, line 9
def to_bool(object = self)
  case object
  when String, Integer, Symbol
    bool_it object
  when Hash
    bool_hash object
  when Array
    bool_array object
  end
end