Class: Step

Inherits:
Hash show all
Defined in:
lib/core/tracking/Step.rb

Overview

This class represents one of the steps inside a history object. It will look something like the following:

"variables"=>[
  {"id"=>3, "value"=>"Grim Fandang", "abs_id"=>-606538658, :uniq_id=>3, 
  "value"=>"Grim Fandango", "abs_id"=>-606538498, :uniq_id=>2
], 
"line"=>1, 
"statement_id"=>625, 
"action"=>"var='Grim Fandango'.chop"}

Instance Method Summary collapse

Methods inherited from Hash

#write

Constructor Details

#initialize(line, statement_id, variables, action) ⇒ Step

Returns a new instance of Step.

Parameters:

  • variables

    TODO I’m not sure whether this should be the variables that have changed or just the ones available on this line. I think it is only the variables that change value.



19
20
21
22
23
24
25
26
27
# File 'lib/core/tracking/Step.rb', line 19

def initialize(line,statement_id,variables,action)
  super()
  self['variables'] = variables
  self['line'] = line
  self['statement_id'] = statement_id
  # TODO  action can proably be dropped - or just replaced with statement.write - I don't
  #       think to_literal_string is useful.
  self['action'] = action
end

Instance Method Details

#cauldron_method_callsObject



48
49
50
# File 'lib/core/tracking/Step.rb', line 48

def cauldron_method_calls
  return ["['statement_id']"]
end

#copyObject



43
44
45
46
# File 'lib/core/tracking/Step.rb', line 43

def copy
  # TODO  Don't use Marshal - do it properly
  return Marshal.load(Marshal.dump(self))
end

#find_data_for_variable(id) ⇒ Object

Returns the data for the variable thats id was specified.

Parameters:

  • id

    The id of the variable thats id should be returned



33
34
35
36
# File 'lib/core/tracking/Step.rb', line 33

def find_data_for_variable(id)
  missing_variable = lambda { raise StandardError.new('Couldn\'t find information on variable '+id.to_s) }
  return self['variables'].detect(missing_variable) {|x| x['id']==id} 
end

#to_var(id = nil, uniq_id = nil) ⇒ Object



38
39
40
41
# File 'lib/core/tracking/Step.rb', line 38

def to_var(id=nil,uniq_id=nil)
  # TODO  I don't know if the the block is used anymore
  return StepVariable.new(self,id) {{:variable_id => id,:uniq_id=>uniq_id}}
end