Top Level Namespace
Defined Under Namespace
Modules: OpenStudio Classes: Hash
Instance Method Summary collapse
-
#typecast_value(variable_type, value, inspect_string = false) ⇒ Object
Typecast Variable Values by a string.
Instance Method Details
#typecast_value(variable_type, value, inspect_string = false) ⇒ Object
Typecast Variable Values by a string.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/openstudio/helpers/string.rb', line 37 def typecast_value(variable_type, value, inspect_string = false) out_value = nil unless value.nil? case variable_type.downcase when 'double' out_value = value.to_f when 'integer' out_value = value.to_i when 'string', 'choice' out_value = inspect_string ? value.inspect : value.to_s when 'bool', 'boolean' # Check if the value is already a boolean if !!value == value out_value = value else if value.casecmp('true').zero? out_value = true elsif value.casecmp('false').zero? out_value = false else raise "Can't cast to a bool from a value of '#{value}' of class '#{value.class}'" end end else raise "Unknown variable type of '#{@variable['type']}'" end end out_value end |