Class: Swarm::ConditionalExpression
Instance Attribute Summary
Attributes inherited from HiveDweller
#hive, #id
Instance Method Summary
collapse
#add_and_apply_child, #add_child, #create_child_expression, #kick_off_children
Methods inherited from Expression
#_apply, #_reply, #apply, #arguments, #branch_position, #command, #evaluator, inherited, #meets_conditions?, #node, #node_at_position, #parent, #replied?, #replied_at, #reply, #reply_to_parent, #root?, storage_type
Methods inherited from HiveDweller
#==, all, #attributes, #change_attribute, #changed?, create, #delete, each, fetch, ids, inherited, #initialize, many_to_one, #new?, new_from_storage, one_to_many, #reload!, #save, #set_attributes, set_columns, #storage, #storage_id, storage_id_for_key, storage_type, #to_hash
Instance Method Details
#branch_condition_met? ⇒ Boolean
32
33
34
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 32
def branch_condition_met?
evaluator.check_condition(command, arguments["condition"])
end
|
#move_on_from(child) ⇒ Object
15
16
17
18
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 15
def move_on_from(child)
self.workitem = child.workitem
reply
end
|
#original_tree ⇒ Object
5
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 5
alias_method :original_tree, :tree
|
#select_branch ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 24
def select_branch
if branch_condition_met?
original_tree["true"]
else
original_tree["false"]
end
end
|
#tree ⇒ Object
20
21
22
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 20
def tree
@tree ||= select_branch || []
end
|
#work ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 7
def work
if tree.empty?
reply
else
kick_off_children([0])
end
end
|