lib/lumberg/whm.rb
# Recursively converts values of 0 or 1 to true or false
Recursively converts values of 0 or 1 to true or false
Recursively converts values of 0 or 1 to true or false
def to_bool(hash, *keys)
        if keys.empty?
          keys = [:all]
        else
          keys.flatten!
        end
        if hash.is_a?(Hash)
          hash = Hash[
            hash.map {|key, value|
              value = to_bool(value, keys) if value.is_a?(Hash)
              value = value.map {|elem| to_bool(elem, keys) } if value.is_a?(Array)
              if (keys.first == :all) || (keys.include?(key) || (keys.include?(key.to_sym)))
                value = (value.to_s.match(/0|1/) ? value.to_i == 1 : value)
              end
              [key, value]
          }]
        end
        hash
      end
def to_bool ( hash , * keys ) if keys . empty? keys = [ :all ] else keys . flatten! end if hash . is_a? ( Hash ) hash = Hash [ hash . map { | key , value | value = to_bool ( value , keys ) if value . is_a? ( Hash ) value = value . map { | elem | to_bool ( elem , keys ) } if value . is_a? ( Array ) if ( keys . first == :all ) || ( keys . include? ( key ) || ( keys . include? ( key . to_sym ) ) ) value = ( value . to_s . match ( / 0|1 / ) ? value . to_i == 1 : value ) end [ key , value ] } ] end hash end
Recursively converts values of 0 or 1 to true or false
Recursively converts values of 0 or 1 to true or false
# recurse
hash
keys