module Rtml::ReverseEngineering::Simulator::VariableLookup # Checks a value to see if it references a TML variable; if so, it resolves that variable into its value; # otherwise, the original value is returned. def resolve(value, all_variables, known_variable_types) if value =~ /^tmlvar:(.*)$/ lookup_variable_value($~[1], all_variables, known_variable_types) else value end end # Finds the variable in the all_variables hash whose name matches the specified name (string or symbol), and then # returns its value. If that value is an instance of +Rtml::ReverseEngineering::Simulator::VariableValue+, calls # the #value method on that object instead. # # If the variable is not found, then a default value will be returned depending on its type. def lookup_variable_value(name, all_variables, known_variable_types) all_variables.each do |var_name, varval| if var_name.to_s == name return(varval.kind_of?(Rtml::ReverseEngineering::Simulator::VariableValue) ? varval.value : varval) end end default_value_for_type(known_variable_types[name]) end def default_value_for_type(type) case type when :integer then 1 else "generic" end end end