Module: Lumberg::Whm

Defined in:
lib/lumberg/whm.rb,
lib/lumberg/whm/dns.rb,
lib/lumberg/whm/base.rb,
lib/lumberg/whm/cert.rb,
lib/lumberg/whm/server.rb,
lib/lumberg/whm/account.rb,
lib/lumberg/whm/reseller.rb,
lib/lumberg/whm/transfer_tool.rb

Defined Under Namespace

Classes: Account, Base, Cert, Dns, Reseller, Server, TransferTool

Class Method Summary collapse

Class Method Details

.from_bool(input) ⇒ Object

Converts boolean values to 0 or 1


55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lumberg/whm.rb', line 55

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

.symbolize_keys(arg) ⇒ Object

Converts keys to symbols


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lumberg/whm.rb', line 14

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

.to_bool(hash, *keys) ⇒ Object

Recursively converts values of 0 or 1 to true or false


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lumberg/whm.rb', line 31

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