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, define_getter, define_setter, #delete, each, fetch, ids, inherited, #initialize, many_to_one, #new?, new_from_storage, one_to_many, reify_from_hash, #reload!, #save, #set_attributes, set_columns, #storage, #storage_id, storage_id_for_key, storage_type, #to_hash
Instance Method Details
#branch_condition_met? ⇒ Boolean
34
35
36
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 34
def branch_condition_met?
evaluator.check_condition(command, arguments["condition"])
end
|
#move_on_from(child) ⇒ Object
17
18
19
20
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 17
def move_on_from(child)
self.workitem = child.workitem
reply
end
|
#original_tree ⇒ Object
7
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 7
alias original_tree tree
|
#select_branch ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 26
def select_branch
if branch_condition_met?
original_tree["true"]
else
original_tree["false"]
end
end
|
#tree ⇒ Object
22
23
24
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 22
def tree
@tree ||= select_branch || []
end
|
#work ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/swarm/expressions/conditional_expression.rb', line 9
def work
if tree.empty?
reply
else
kick_off_children([0])
end
end
|