Sha256: dc2f0c33ec30144ef3e657a7800f3d8f2bd7979065c5130995a36547cd2a2fbf

Contents?: true

Size: 901 Bytes

Versions: 10

Compression:

Stored size: 901 Bytes

Contents

# Typecast Variable Values by a string.
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.downcase == 'true'
            out_value = true
          elsif value.downcase == 'false'
            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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
openstudio-analysis-1.0.0.rc19 lib/openstudio/helpers/string.rb
openstudio-analysis-1.0.0.rc18 lib/openstudio/helpers/string.rb
openstudio-analysis-1.0.0.rc17 lib/openstudio/helpers/string.rb
openstudio-analysis-1.0.0.rc16 lib/openstudio/helpers/string.rb
openstudio-analysis-1.0.0.rc15 lib/openstudio/helpers/string.rb
openstudio-analysis-1.0.0.rc14 lib/openstudio/helpers/string.rb
openstudio-analysis-1.0.0.rc13 lib/openstudio/helpers/string.rb
openstudio-analysis-1.0.0.rc12 lib/openstudio/helpers/string.rb
openstudio-analysis-1.0.0.rc11 lib/openstudio/helpers/string.rb
openstudio-analysis-1.0.0.rc10 lib/openstudio/helpers/string.rb