Sha256: cc2a7f589023fa6735bb2bbb6d7eacb912444dd67f9da7500d19dc4d096fb47b

Contents?: true

Size: 1.84 KB

Versions: 6

Compression:

Stored size: 1.84 KB

Contents

module Lumberg
  module Whm
    autoload :Base,         'lumberg/whm/base'
    autoload :Server,       'lumberg/whm/server'
    autoload :Account,      'lumberg/whm/account'
    autoload :Dns,          'lumberg/whm/dns'
    autoload :Reseller,     'lumberg/whm/reseller'
    autoload :Cert,         'lumberg/whm/cert'
    autoload :TransferTool, 'lumberg/whm/transfer_tool'

    class << self

      # Converts keys to symbols
      def symbolize_keys(arg)
        case arg
          when Array
            arg.map { |elem| symbolize_keys elem }
          when Hash
            Hash[
              arg.map { |key, value|
                k = key.is_a?(String) ? key.gsub('-', '_').to_sym : key
                v = symbolize_keys value
                [k,v]
              }]
          else
            arg
        end
      end

      # 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|
              # recurse
              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

      # Converts boolean values to 0 or 1
      def from_bool(input)
        if input == false
          0
        elsif input == true
          1
        elsif input.is_a?(Hash)
          Hash[
            input.map {|k,v|
              v = from_bool(v)
              [k,v]
            }
          ]
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lumberg-4.1.0 lib/lumberg/whm.rb
lumberg-4.0.0 lib/lumberg/whm.rb
lumberg-3.1.0 lib/lumberg/whm.rb
lumberg-3.0.0 lib/lumberg/whm.rb
lumberg-2.0.1 lib/lumberg/whm.rb
lumberg-2.0.0 lib/lumberg/whm.rb