Module: PuppetX::Sensu::ToType

Defined in:
lib/puppet_x/sensu/to_type.rb

Instance Method Summary collapse

Instance Method Details

#to_type(value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/puppet_x/sensu/to_type.rb', line 4

def to_type(value)
  if value.is_a?(Hash)
    new = Hash.new
    value.each { |k,v| new[k] = to_type v }
    new
  elsif value.is_a?(Array)
    value.collect { |v| to_type v }
  else
    case value
    when true, 'true', 'True', :true
      true
    when false, 'false', 'False', :false
      false
    when :undef
      'undef'
    when /^([0-9])+$/
      value.to_i
    else
      value
    end
  end
end