Module: Utilise::Augment::Bool
Overview
Extends classes that could be treated as a boolean
Instance Method Summary collapse
-
#bool_array(array) ⇒ Object
Iterates through array and updates each element to a boolean if it matches rules.
-
#bool_hash(hash) ⇒ Object
Iterates through hash and updates each key value to a boolean if it matches rules.
-
#bool_it(object) ⇒ Object
Returns boolean value if object matches rules.
-
#to_bool(object = self) ⇒ Object
Returns bool based on object passed.
Instance Method Details
#bool_array(array) ⇒ Object
Iterates through array and updates each element to a boolean if it matches rules
35 36 37 38 39 40 |
# 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) ⇒ Object
Iterates through hash and updates each key value to a boolean if it matches rules
24 25 26 27 28 29 |
# 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) ⇒ Object
Returns boolean value if object matches rules
46 47 48 49 50 51 52 53 |
# 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 |