Module: Rtml::ReverseEngineering::Simulator::VariableLookup

Included in:
Rtml::ReverseEngineering::Simulator, VariableValue
Defined in:
lib/rtml/reverse_engineering/simulator/variable_lookup.rb

Instance Method Summary collapse

Instance Method Details

#default_value_for_type(type) ⇒ Object



26
27
28
29
30
31
# File 'lib/rtml/reverse_engineering/simulator/variable_lookup.rb', line 26

def default_value_for_type(type)
  case type
    when :integer then 1
    else "generic"
  end
end

#lookup_variable_value(name, all_variables, known_variable_types) ⇒ Object

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.



17
18
19
20
21
22
23
24
# File 'lib/rtml/reverse_engineering/simulator/variable_lookup.rb', line 17

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

#resolve(value, all_variables, known_variable_types) ⇒ Object

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.



4
5
6
7
8
9
10
# File 'lib/rtml/reverse_engineering/simulator/variable_lookup.rb', line 4

def resolve(value, all_variables, known_variable_types)
  if value =~ /^tmlvar:(.*)$/
    lookup_variable_value($~[1], all_variables, known_variable_types)
  else
    value
  end
end