Top Level Namespace

Defined Under Namespace

Modules: OpenStudio Classes: Hash, String

Instance Method Summary collapse

Instance Method Details

#typecast_value(variable_type, value, inspect_string = false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/openstudio/helpers/string.rb', line 23

def typecast_value(variable_type, value, inspect_string = false)
  out_value = nil
  case variable_type.downcase
    when 'double'
      out_value = value.to_f
    when 'integer'
      out_value = value.to_i
    when 'string'
      out_value = inspect_string ? value.inspect : value.to_s
    when 'choice'
      out_value = value.inspect
    when 'bool', 'boolean'
      if value.downcase == 'true'
        out_value = true
      elsif value.downcase == 'false'
        out_value = false
      else
        fail "Can't cast to a bool from a value of '#{value}' of class '#{value.class}'"
      end
    else
      fail "Unknown variable type of '#{@variable['type']}'"
  end

  out_value
end