Class: Toaster::TransitionEdge

Inherits:
Object
  • Object
show all
Defined in:
lib/toaster/state/transition_edge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_from, node_to, conditions = [], transition = nil) ⇒ TransitionEdge

Returns a new instance of TransitionEdge.



13
14
15
16
17
18
19
# File 'lib/toaster/state/transition_edge.rb', line 13

def initialize(node_from, node_to, conditions=[], transition=nil)
  @node_from = node_from
  @node_to = node_to
  @disjunctive_conditions = conditions
  @disjunctive_conditions = [] if !conditions
  @transition = transition
end

Instance Attribute Details

#disjunctive_conditionsObject

Returns the value of attribute disjunctive_conditions.



11
12
13
# File 'lib/toaster/state/transition_edge.rb', line 11

def disjunctive_conditions
  @disjunctive_conditions
end

#node_fromObject

Returns the value of attribute node_from.



11
12
13
# File 'lib/toaster/state/transition_edge.rb', line 11

def node_from
  @node_from
end

#node_toObject

Returns the value of attribute node_to.



11
12
13
# File 'lib/toaster/state/transition_edge.rb', line 11

def node_to
  @node_to
end

#transitionObject

Returns the value of attribute transition.



11
12
13
# File 'lib/toaster/state/transition_edge.rb', line 11

def transition
  @transition
end

Instance Method Details

#matches_parameters?(task_parameters) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/toaster/state/transition_edge.rb', line 34

def matches_parameters?(task_parameters)
  @disjunctive_conditions.each do |condition|
    all_contained = true
    condition.each do |key,value|
      contained = false
      task_parameters.each do |tp_key,tp_val|
        if key == tp_key
          if value.eql?(tp_val)
            contained = true
            break
          end
        end
      end
      if !contained
        all_contained = false
        break
      end
    end
    return true if all_contained
  end
  return false
end

#matches_states?(prestate, poststate) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
# File 'lib/toaster/state/transition_edge.rb', line 57

def matches_states?(prestate, poststate)
  return false if !@node_from.subset_of?(prestate)
  return false if !@node_to.subset_of?(poststate)
  return true
end

#represented_taskObject

each state transition represents the execution of an automation task



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/toaster/state/transition_edge.rb', line 22

def represented_task()
  t = @node_to.preceding_task()
  if @node_from.properties.include?("__task_num__") && @node_to.properties.include?("__task_num__")
    # in a "backwards" transition no particular task execution is represented
    if @node_from.properties["__task_num__"] > @node_to.properties["__task_num__"]
      return nil
    end
  end
  return t if t
  return @node_from.succeeding_task
end