Class: Flor::Pro::Shuffle

Inherits:
Flor::Procedure show all
Defined in:
lib/flor/pcore/shuffle.rb

Constant Summary

Constants inherited from Flor::Procedure

Flor::Procedure::RVARS, Flor::Procedure::TRUE_ATTS

Instance Attribute Summary

Attributes inherited from Node

#message

Instance Method Summary collapse

Methods inherited from Flor::Procedure

[], core?, #debug_msg, #debug_tree, #end, #flank, #heap, inherited, make, names, #prepare_on_receive_last, #trigger_on_error

Methods inherited from Node

#child_id, #cnodes, #cnodes_any?, #cnodes_empty?, #deref, #descendant_of?, #domain, #exid, #fei, #from, #h, #initialize, #lookup_tree, #lookup_value, #message_or_node_payload, #nid, #node_closed?, #node_ended?, #node_open?, #node_payload, #node_payload_ret, #node_status, #node_status_flavour, #on_error_parent, #parent, #payload, #payload_ret, #point, #reheap, #to_procedure_node, #tree

Constructor Details

This class inherits a constructor from Flor::Node

Instance Method Details

#pre_executeObject



46
47
48
49
50
51
52
# File 'lib/flor/pcore/shuffle.rb', line 46

def pre_execute

  unatt_unkeyed_children

  @node['atts'] = []
  @node['rets'] = []
end

#receive_lastObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/flor/pcore/shuffle.rb', line 54

def receive_last

  arr =
    (@node['rets'] + [ node_payload_ret ])
      .find { |r| r.is_a?(Array) }

  fail Flor::FlorError.new("no array to #{heap}") unless arr

  cnt =
    att('count', nil) ||
    @node['rets'].find { |r| r.is_a?(Integer) }

  ret = arr.sample(cnt || arr.size)
  ret = ret.first if cnt == nil && heap == 'sample'

  wrap('ret' => ret)
end