Class: OpenWFE::Extras::CsvParticipant
- Inherits:
-
Object
- Object
- OpenWFE::Extras::CsvParticipant
- Includes:
- LocalParticipant
- Defined in:
- lib/openwfe/extras/participants/csvparticipants.rb
Overview
Using CSV files to transform workitems This concept is called “decision participant” in OpenWFEja, here it’s simply called “csv participant”.
See CsvTable for an explanation of the core concept behind a CsvParticipant
An example :
class TestDefinition0 < ProcessDefinition
sequence do
set :field => "weather", :value => "cloudy"
set :field => "month", :value => "may"
decision
_print "${f:take_umbrella?}"
end
end
csvParticipant = CsvParticipant.new(
"""
in:weather, in:month, out:take_umbrella?
,,
raining, , yes
sunny, , no
cloudy, june, yes
cloudy, may, yes
cloudy, , no
""")
engine.register_participant("decision", csvParticipant)
# ...
engine.launch(new OpenWFE::LaunchItem(TestDefinition0)
Note that the CsvParticipant constructor also accepts a block.
Instance Attribute Summary collapse
-
#csv_table ⇒ Object
Returns the value of attribute csv_table.
Instance Method Summary collapse
-
#consume(workitem) ⇒ Object
This is the method called by the engine (actually the ParticipantExpression) when handling a workitem to this participant.
-
#initialize(csv_data = nil, &block) ⇒ CsvParticipant
constructor
Builds a new CsvParticipant instance, csv_data or the block may contain a File instance, a String or an Array of Array of String instances.
Constructor Details
#initialize(csv_data = nil, &block) ⇒ CsvParticipant
Builds a new CsvParticipant instance, csv_data or the block may contain a File instance, a String or an Array of Array of String instances.
100 101 102 103 104 105 106 107 |
# File 'lib/openwfe/extras/participants/csvparticipants.rb', line 100 def initialize (csv_data=nil, &block) super() csv_data = block.call if block @csv_table = Rufus::DecisionTable.new csv_data end |
Instance Attribute Details
#csv_table ⇒ Object
Returns the value of attribute csv_table.
93 94 95 |
# File 'lib/openwfe/extras/participants/csvparticipants.rb', line 93 def csv_table @csv_table end |
Instance Method Details
#consume(workitem) ⇒ Object
This is the method called by the engine (actually the ParticipantExpression) when handling a workitem to this participant.
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/openwfe/extras/participants/csvparticipants.rb', line 113 def consume (workitem) fe = get_flow_expression workitem @csv_table.transform!(FlowDict.new(fe, workitem, 'f')) # # default_prefix set to 'f' reply_to_engine workitem end |