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
def make
process_definition :name => "test0", :revision => "0" do
sequence do
set :field => "weather", :value => "cloudy"
set :field => "month", :value => "may"
decision
_print "${f:take_umbrella?}"
end
end
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.
107 108 109 110 111 112 113 114 |
# File 'lib/openwfe/extras/participants/csvparticipants.rb', line 107 def initialize (csv_data=nil, &block) super() csv_data = block.call if block @csv_table = CsvTable.new(csv_data) end |
Instance Attribute Details
#csv_table ⇒ Object
Returns the value of attribute csv_table.
99 100 101 |
# File 'lib/openwfe/extras/participants/csvparticipants.rb', line 99 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.
120 121 122 123 124 |
# File 'lib/openwfe/extras/participants/csvparticipants.rb', line 120 def consume (workitem) fe = get_flow_expression(workitem) workitem = @csv_table.transform_wi(fe, workitem) reply_to_engine(workitem) end |