openwferu-extras 0.9.16 → 0.9.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2008, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+
34
+ #
35
+ # "made in Japan"
36
+ #
37
+ # John Mettraux at openwfe.org
38
+ #
39
+
40
+ require 'openwfe/participants/participants'
41
+ require 'openwfe/extras/misc/basecamp'
42
+
43
+
44
+ module OpenWFE
45
+ module Extras
46
+
47
+ class BasecampParticipant
48
+ include OpenWFE::LocalParticipant
49
+ include OpenWFE::TemplateMixin
50
+
51
+ def initialize (params, &block)
52
+
53
+ super()
54
+
55
+ @template = params[:template]
56
+ @block_template = block
57
+
58
+ @company_id = params[:company_id]
59
+ #@project_id = params[:project_id]
60
+
61
+ @responsible_party_id = params[:responsible_party_id]
62
+ @todo_list_id = params[:todo_list_id]
63
+
64
+ ssl = params[:ssl]
65
+ ssl = true if ssl == nil
66
+
67
+ @camp = Basecamp.new(
68
+ params[:host], params[:username], params[:password], ssl)
69
+ end
70
+
71
+ def consume (workitem)
72
+
73
+ text = workitem['todo_text'] || eval_template(wi)
74
+
75
+ resp = workitem['todo_responsible_party'] || @responsible_party_id
76
+ list = workitem['toto_list_id'] || @todo_list_id
77
+
78
+ todo = @camp.create_item list, text, resp
79
+
80
+ workitem['todo_id'] = todo.id
81
+
82
+ reply_to_engine workitem
83
+ end
84
+ end
85
+ end
86
+ end
87
+
@@ -1,6 +1,6 @@
1
1
  #
2
2
  #--
3
- # Copyright (c) 2007, John Mettraux, OpenWFE.org
3
+ # Copyright (c) 2007-2008, John Mettraux, OpenWFE.org
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
@@ -37,12 +37,12 @@
37
37
  # John Mettraux at openwfe.org
38
38
  #
39
39
 
40
+ #require 'rubygems'
41
+ require 'rufus/decision' # gem 'rufus-decision'
42
+
40
43
  require 'openwfe/utils'
41
44
  require 'openwfe/util/dollar'
42
45
  require 'openwfe/participants/participant'
43
- require 'openwfe/extras/util/csvtable'
44
-
45
- include OpenWFE
46
46
 
47
47
 
48
48
  module OpenWFE
@@ -90,8 +90,7 @@ module Extras
90
90
  class CsvParticipant
91
91
  include LocalParticipant
92
92
 
93
- attr_accessor \
94
- :csv_table
93
+ attr_accessor :csv_table
95
94
 
96
95
  #
97
96
  # Builds a new CsvParticipant instance, csv_data or the block
@@ -104,7 +103,7 @@ module Extras
104
103
 
105
104
  csv_data = block.call if block
106
105
 
107
- @csv_table = CsvTable.new(csv_data)
106
+ @csv_table = Rufus::DecisionTable.new csv_data
108
107
  end
109
108
 
110
109
  #
@@ -112,9 +111,14 @@ module Extras
112
111
  # ParticipantExpression) when handling a workitem to this participant.
113
112
  #
114
113
  def consume (workitem)
115
- fe = get_flow_expression(workitem)
116
- workitem = @csv_table.transform_wi(fe, workitem)
117
- reply_to_engine(workitem)
114
+
115
+ fe = get_flow_expression workitem
116
+
117
+ @csv_table.transform!(FlowDict.new(fe, workitem, 'f'))
118
+ #
119
+ # default_prefix set to 'f'
120
+
121
+ reply_to_engine workitem
118
122
  end
119
123
  end
120
124
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  #--
3
- # Copyright (c) 2007, John Mettraux, OpenWFE.org
3
+ # Copyright (c) 2007-2008, John Mettraux, OpenWFE.org
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
@@ -41,8 +41,9 @@
41
41
  require 'yaml'
42
42
  require 'base64'
43
43
 
44
- #require 'openwfe/utils'
45
- #require 'openwfe/rudefinitions'
44
+ #require 'rubygems'
45
+ require 'rufus/sqs' # gem 'rufus-sqs'
46
+
46
47
  require 'openwfe/participants/participant'
47
48
 
48
49
 
@@ -78,12 +79,12 @@ module Extras
78
79
 
79
80
  @queue_name = queue_name
80
81
 
81
- @queue_service = SQS::QueueService.new(host_name)
82
+ @queue_service = Rufus::SQS::QueueService.new host_name
82
83
 
83
- @queue_service.create_queue(@queue_name)
84
+ @queue_service.create_queue @queue_name
84
85
  # make sure the queue exists
85
86
 
86
- @queue = @queue_service.get_queue(@queue_name)
87
+ @queue = @queue_service.get_queue @queue_name
87
88
  end
88
89
 
89
90
  #
@@ -92,9 +93,9 @@ module Extras
92
93
  #
93
94
  def consume (workitem)
94
95
 
95
- msg = encode_workitem(workitem)
96
+ msg = encode_workitem workitem
96
97
 
97
- msg_id = @queue_service.put_message(@queue, msg)
98
+ msg_id = @queue_service.put_message @queue, msg
98
99
 
99
100
  ldebug do
100
101
  "consume() msg sent to queue #{@queue.path} id is #{msg_id}"
@@ -1,6 +1,6 @@
1
1
  #
2
2
  #--
3
- # Copyright (c) 2007, John Mettraux, OpenWFE.org
3
+ # Copyright (c) 2007-2008, John Mettraux, OpenWFE.org
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
@@ -45,24 +45,9 @@
45
45
  # atom-tools' license is X11/MIT
46
46
  #
47
47
 
48
- require 'rubygems'
49
-
50
- begin
51
- #gem 'twitter4r', '0.2.3'
52
- require 'twitter'
53
- rescue LoadError
54
- #
55
- # soft dependency on 'atom-tools'
56
- #
57
- puts
58
- puts
59
- puts "'twitter4r' is missing. You can install it with :"
60
- puts
61
- puts " [sudo] gem install -y twitter4r"
62
- puts
63
- puts
64
- exit 1
65
- end
48
+ #require 'rubygems'
49
+ #gem 'twitter4r', '0.2.3'
50
+ require 'twitter' # gem 'twitter4r'
66
51
 
67
52
  require 'openwfe/utils'
68
53
  require 'openwfe/participants/participant'
metadata CHANGED
@@ -1,33 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: openwferu-extras
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.9.16
7
- date: 2007-11-19 00:00:00 +09:00
8
- summary: OpenWFEru extras (sqs, csv, ...)
9
- require_paths:
10
- - lib
11
- email: john at openwfe dot org
12
- homepage: http://openwferu.rubyforge.org/
13
- rubyforge_project:
14
- description:
15
- autorequire: openwferu-extras
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.9.17
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - John Mettraux
8
+ autorequire: openwferu-extras
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-03-17 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: john at openwfe dot org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
31
24
  files:
32
25
  - lib/openwfe/extras/engine
33
26
  - lib/openwfe/extras/engine/db_persisted_engine.rb
@@ -38,27 +31,40 @@ files:
38
31
  - lib/openwfe/extras/listeners/sqslisteners.rb
39
32
  - lib/openwfe/extras/misc
40
33
  - lib/openwfe/extras/misc/activityfeed.rb
34
+ - lib/openwfe/extras/misc/basecamp.rb
41
35
  - lib/openwfe/extras/participants
42
36
  - lib/openwfe/extras/participants/activeparticipants.rb
43
37
  - lib/openwfe/extras/participants/atomfeed_participants.rb
44
38
  - lib/openwfe/extras/participants/atompub_participants.rb
39
+ - lib/openwfe/extras/participants/basecamp_participants.rb
45
40
  - lib/openwfe/extras/participants/csvparticipants.rb
46
41
  - lib/openwfe/extras/participants/sqsparticipants.rb
47
42
  - lib/openwfe/extras/participants/twitterparticipants.rb
48
- - lib/openwfe/extras/util
49
- - lib/openwfe/extras/util/csvtable.rb
50
- - lib/openwfe/extras/util/sqs.rb
51
- test_files: []
52
-
43
+ has_rdoc: false
44
+ homepage: http://openwferu.rubyforge.org/
45
+ post_install_message:
53
46
  rdoc_options: []
54
47
 
55
- extra_rdoc_files: []
56
-
57
- executables: []
58
-
59
- extensions: []
60
-
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
61
62
  requirements: []
62
63
 
63
- dependencies: []
64
+ rubyforge_project:
65
+ rubygems_version: 0.9.5
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: OpenWFEru extras (sqs, csv, ...)
69
+ test_files: []
64
70
 
@@ -1,620 +0,0 @@
1
- #
2
- #--
3
- # Copyright (c) 2007, John Mettraux, OpenWFE.org
4
- # All rights reserved.
5
- #
6
- # Redistribution and use in source and binary forms, with or without
7
- # modification, are permitted provided that the following conditions are met:
8
- #
9
- # . Redistributions of source code must retain the above copyright notice, this
10
- # list of conditions and the following disclaimer.
11
- #
12
- # . Redistributions in binary form must reproduce the above copyright notice,
13
- # this list of conditions and the following disclaimer in the documentation
14
- # and/or other materials provided with the distribution.
15
- #
16
- # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
- # used to endorse or promote products derived from this software without
18
- # specific prior written permission.
19
- #
20
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
- # POSSIBILITY OF SUCH DAMAGE.
31
- #++
32
- #
33
-
34
- #
35
- # "made in Japan"
36
- #
37
- # John Mettraux at openwfe.org
38
- #
39
-
40
- require 'csv'
41
- require 'open-uri'
42
-
43
- require 'openwfe/utils'
44
- require 'openwfe/util/dollar'
45
- require 'openwfe/workitem'
46
-
47
- include OpenWFE
48
-
49
-
50
- module OpenWFE
51
- module Extras
52
-
53
- #
54
- # A regexp for checking if a string is a numeric Ruby range
55
- #
56
- RUBY_NUMERIC_RANGE_REGEXP = Regexp.compile(
57
- "^\\d+(\\.\\d+)?\\.{2,3}\\d+(\\.\\d+)?$")
58
-
59
- #
60
- # A regexp for checking if a string is an alpha Ruby range
61
- #
62
- RUBY_ALPHA_RANGE_REGEXP = Regexp.compile(
63
- "^([A-Za-z])(\\.{2,3})([A-Za-z])$")
64
-
65
- #
66
- # If the string contains a Ruby range definition
67
- # (ie something like "93.0..94.5" or "56..72"), it will return
68
- # the Range instance.
69
- # Will return nil else.
70
- #
71
- # The Ruby range returned (if any) will accept String or Numeric,
72
- # ie (4..6).include?("5") will yield true.
73
- #
74
- def to_ruby_range (s)
75
-
76
- range = if RUBY_NUMERIC_RANGE_REGEXP.match(s)
77
-
78
- eval s
79
- else
80
-
81
- m = RUBY_ALPHA_RANGE_REGEXP.match(s)
82
-
83
- if m
84
- eval "'#{m[1]}'#{m[2]}'#{m[3]}'"
85
- else
86
- nil
87
- end
88
- end
89
-
90
- class << range
91
-
92
- alias :old_include? :include?
93
-
94
- def include? (elt)
95
-
96
- elt = if first.is_a?(Numeric)
97
- Float(elt)
98
- else
99
- elt
100
- end
101
-
102
- old_include?(elt)
103
- end
104
-
105
- end if range
106
-
107
- range
108
- end
109
-
110
- #
111
- # A 'CsvTable' is called a 'decision table' in OpenWFEja (the initial
112
- # Java implementation of OpenWFE).
113
- #
114
- # A csv table is a description of a set of rules as a CSV (comma
115
- # separated values) file. Such a file can be edited / generated by
116
- # a spreadsheet (Excel, Google spreadsheets, Gnumeric, ...)
117
- #
118
- # The following CSV file
119
- #
120
- # in:topic,in:region,out:team_member
121
- # sports,europe,Alice
122
- # sports,,Bob
123
- # finance,america,Charly
124
- # finance,europe,Donald
125
- # finance,,Ernest
126
- # politics,asia,Fujio
127
- # politics,america,Gilbert
128
- # politics,,Henry
129
- # ,,Zach
130
- #
131
- # embodies a rule for distributing items (piece of news) labelled with a
132
- # topic and a region to various members of a team.
133
- # For example, all news about finance from Europe are to be routed to
134
- # Donald.
135
- #
136
- # Evaluation occurs row by row. The "in out" row states which field
137
- # is considered at input and which are to be modified if the "ins" do
138
- # match.
139
- #
140
- # The default behaviour is to change the value of the "outs" if all the
141
- # "ins" match and then terminate.
142
- # An empty "in" cell means "matches any".
143
- #
144
- # Enough words, some code :
145
- #
146
- # table = CsvTable.new("""
147
- # in:topic,in:region,out:team_member
148
- # sports,europe,Alice
149
- # sports,,Bob
150
- # finance,america,Charly
151
- # finance,europe,Donald
152
- # finance,,Ernest
153
- # politics,asia,Fujio
154
- # politics,america,Gilbert
155
- # politics,,Henry
156
- # ,,Zach
157
- # """)
158
- #
159
- # h = {}
160
- # h["topic"] = "politics"
161
- #
162
- # table.transform(h)
163
- #
164
- # puts h["team_member"]
165
- # # will yield "Henry" who takes care of all the politics stuff,
166
- # # except for Asia and America
167
- #
168
- # '>', '>=', '<' and '<=' can be put in front of individual cell values :
169
- #
170
- # table = CsvTable.new("""
171
- # ,
172
- # in:fx, out:fy
173
- # ,
174
- # >100,a
175
- # >=10,b
176
- # ,c
177
- # """)
178
- #
179
- # h = { 'fx' => '10' }
180
- # table.transform(h)
181
- #
182
- # require 'pp'; pp h
183
- # # will yield { 'fx' => '10', 'fy' => 'b' }
184
- #
185
- # Such comparisons are done after the elements are transformed to float
186
- # numbers. By default, non-numeric arguments will get compared as Strings.
187
- #
188
- # Ruby ranges are also accepted in cells.
189
- #
190
- # in:f0,out:result
191
- # ,
192
- # 0..32,low
193
- # 33..66,medium
194
- # 67..100,high
195
- #
196
- # will set the field 'result' to 'low' for f0 => 24
197
- #
198
- # Disclaimer : the decision / CSV table system is no replacement for
199
- # full rule engines with forward and backward chaining, RETE implementation
200
- # and the like...
201
- #
202
- #
203
- # Options :
204
- #
205
- # You can put options on their own in a cell BEFORE the line containing
206
- # "in:xxx" and "out:yyy" (ins and outs).
207
- #
208
- # Currently, two options are supported, "ignorecase" and "through".
209
- #
210
- # * "ignorecase", if found by the CsvTable will make any match (in the "in"
211
- # columns) case unsensitive.
212
- #
213
- # * "through", will make sure that EVERY row is evaluated and potentially
214
- # applied. The default behaviour (without "through"), is to stop the
215
- # evaluation after applying the results of the first matching row.
216
- #
217
- # * "accumulate", behaves as with "through" set but instead of overriding
218
- # values each time a match is found, will gather them in an array.
219
- #
220
- # accumulate
221
- # in:f0,out:result
222
- # ,
223
- # ,normal
224
- # >10,large
225
- # >100,xl
226
- #
227
- # will yield { result => [ 'normal', 'large' ]} for f0 => 56
228
- #
229
- # CSV Tables are available to workflows as CsvParticipant.
230
- #
231
- #
232
- # See also :
233
- #
234
- # * http://jmettraux.wordpress.com/2007/02/11/ruby-decision-tables/
235
- # * http://rubyforge.org/viewvc/trunk/openwfe-ruby/test/extras/csv_test.rb?root=openwferu&view=co
236
- #
237
- class CsvTable
238
-
239
- attr_accessor \
240
- :first_match,
241
- :ignore_case,
242
- :header,
243
- :rows,
244
- :accumulate
245
-
246
- #
247
- # The constructor for CsvTable, you can pass a String, an Array
248
- # (of arrays), a File object. The CSV parser coming with Ruby will take
249
- # care of it and a CsvTable instance will be built.
250
- #
251
- def initialize (csv_data)
252
-
253
- @first_match = true
254
- @ignore_case = false
255
- @accumulate = false
256
-
257
- @header = nil
258
- @rows = []
259
-
260
- csv_array = to_csv_array(csv_data)
261
-
262
- csv_array.each do |row|
263
-
264
- next if empty_row? row
265
-
266
- if @header
267
- #@rows << row
268
- @rows << row.collect { |c| c.strip if c }
269
- else
270
- parse_header_row(row)
271
- end
272
- end
273
- end
274
-
275
- #
276
- # Returns the workitem massaged by the csv table
277
- #
278
- def transform_wi (flow_expression, workitem)
279
-
280
- @rows.each do |row|
281
-
282
- if matches?(row, flow_expression, workitem)
283
- apply row, flow_expression, workitem
284
- break if @first_match
285
- end
286
- end
287
-
288
- workitem
289
- end
290
-
291
- #
292
- # Passes a simple Hash instance though the csv table
293
- #
294
- def transform (hash)
295
-
296
- wi = InFlowWorkItem.new()
297
- wi.attributes = hash
298
-
299
- transform_wi(nil, wi).attributes
300
- end
301
-
302
- #
303
- # Outputs back this table as a CSV String
304
- #
305
- def to_csv
306
-
307
- s = ""
308
- s << @header.to_csv
309
- s << "\n"
310
- @rows.each do |row|
311
- s << row.join(",")
312
- s << "\n"
313
- end
314
- s
315
- end
316
-
317
- protected
318
-
319
- def to_csv_array (csv_data)
320
-
321
- return csv_data if csv_data.kind_of?(Array)
322
-
323
- if csv_data.is_a?(URI)
324
- csv_data = csv_data.to_s
325
- end
326
- if OpenWFE::parse_uri(csv_data)
327
- csv_data = open(csv_data)
328
- end
329
-
330
- CSV::Reader.parse(csv_data)
331
- end
332
-
333
- def matches? (row, fexp, wi)
334
-
335
- return false if empty_row?(row)
336
-
337
- #puts
338
- #puts "__row match ?"
339
- #require 'pp'
340
- #pp row
341
-
342
- @header.ins.each_with_index do |in_header, icol|
343
-
344
- in_header = resolve_in_header(in_header)
345
-
346
- value = OpenWFE::dosub(in_header, fexp, wi)
347
-
348
- cell = row[icol]
349
-
350
- next if not cell
351
-
352
- cell = cell.strip
353
-
354
- next if cell.length < 1
355
-
356
- cell = OpenWFE::dosub(cell, fexp, wi)
357
-
358
- #puts "__does '#{value}' match '#{cell}' ?"
359
-
360
- b = if cell[0, 1] == '<' or cell[0, 1] == '>'
361
-
362
- numeric_compare value, cell
363
- else
364
-
365
- range = to_ruby_range cell
366
- if range
367
- range.include?(value)
368
- else
369
- regex_compare value, cell
370
- end
371
- end
372
-
373
- return false unless b
374
- end
375
-
376
- #puts "__row matches"
377
-
378
- true
379
- end
380
-
381
- def regex_compare (value, cell)
382
-
383
- modifiers = 0
384
- modifiers += Regexp::IGNORECASE if @ignore_case
385
-
386
- rcell = Regexp.new(cell, modifiers)
387
-
388
- rcell.match(value)
389
- end
390
-
391
- def numeric_compare (value, cell)
392
-
393
- comparator = cell[0, 1]
394
- comparator += "=" if cell[1, 1] == "="
395
- cell = cell[comparator.length..-1]
396
-
397
- nvalue = narrow(value)
398
- ncell = narrow(cell)
399
-
400
- if nvalue.is_a? String or ncell.is_a? String
401
- value = '"' + value + '"'
402
- cell = '"' + cell + '"'
403
- else
404
- value = nvalue
405
- cell = ncell
406
- end
407
-
408
- s = "#{value} #{comparator} #{cell}"
409
-
410
- #puts "...>>>#{s}<<<"
411
-
412
- begin
413
- return OpenWFE::eval_safely(s, 4)
414
- rescue Exception => e
415
- end
416
-
417
- false
418
- end
419
-
420
- def narrow (s)
421
- begin
422
- return Float(s)
423
- rescue Exception => e
424
- end
425
- s
426
- end
427
-
428
- def resolve_in_header (in_header)
429
-
430
- in_header = "f:#{in_header}" \
431
- if points_to_nothing?(in_header)
432
-
433
- "${#{in_header}}"
434
- end
435
-
436
- def apply (row, fexp, wi)
437
-
438
- #puts "__ apply() wi.class : #{wi.class.name}"
439
-
440
- @header.outs.each_with_index do |out_header, icol|
441
-
442
- next unless out_header
443
-
444
- value = row[icol]
445
-
446
- next unless value
447
- #next unless value.strip.length > 0
448
- next unless value.length > 0
449
-
450
- value = OpenWFE::dosub(value, fexp, wi)
451
-
452
- #puts "___ value.class:#{value.class}"
453
- #puts "___ value:'#{value}'"
454
- #puts "___ value:'"+value+"'"
455
-
456
- type, target = points_at(out_header)
457
-
458
- #puts "___ t:'#{type}' target:'#{target}'"
459
-
460
- value = accumulate_values(type, target, value, wi, fexp) \
461
- if @accumulate
462
-
463
- if type == "v"
464
- fexp.set_variable(target, value) if fexp
465
- elsif type == "f"
466
- wi.set_attribute(target, value)
467
- elsif type == "r"
468
- OpenWFE::instance_eval_safely(self, value, 3)
469
- end
470
- end
471
- end
472
-
473
- #
474
- # 'accumulate' is on, this method got called to compute the
475
- # new value.
476
- #
477
- # If it finds nothing in the target field, the new value is
478
- # value.
479
- # If there is already a value and its an array, the new value
480
- # will be current_array + value.
481
- # Else the two values (current and new) are combined into an array.
482
- #
483
- # Sorry, if you want f([ x ], y) -> [[ x ], y]... It's not
484
- # implemented like that.
485
- #
486
- def accumulate_values (type, target, value, workitem, fexp)
487
-
488
- current_value = case type
489
- when 'v'
490
- if fexp
491
- fexp.lookup_variable target
492
- else
493
- nil
494
- end
495
- when 'f'
496
- workitem.lookup_attribute target
497
- when 'r'
498
- nil
499
- end
500
-
501
- return value unless current_value
502
-
503
- return current_value + Array(value) \
504
- if current_value.is_a?(Array)
505
-
506
- [ current_value, value ]
507
- end
508
-
509
- def parse_header_row (row)
510
-
511
- row.each_with_index do |cell, icol|
512
-
513
- next unless cell
514
-
515
- cell = cell.strip
516
- s = cell.downcase
517
-
518
- if s == "ignorecase" or s == "ignore_case"
519
- @ignore_case = true
520
- next
521
- end
522
-
523
- if s == "through"
524
- @first_match = false
525
- next
526
- end
527
-
528
- if s == "accumulate"
529
- @first_match = false
530
- @accumulate = true
531
- next
532
- end
533
-
534
- if OpenWFE::starts_with(cell, "in:") or OpenWFE::starts_with(cell, "out:")
535
- @header = Header.new unless @header
536
- @header.add cell, icol
537
- end
538
- end
539
- end
540
-
541
- def empty_row? (row)
542
-
543
- return true unless row
544
- return true if (row.length == 1 and not row[0])
545
- row.each do |cell|
546
- return false if cell
547
- end
548
- true
549
- end
550
-
551
- def points_to_nothing? (label)
552
- (not points_to_variable? label) and \
553
- (not points_to_field? label) and \
554
- (not points_to_ruby? label)
555
- end
556
- def points_at (label)
557
- v = points_to_variable? label
558
- return "v", v if v
559
- r = points_to_ruby? label
560
- return "r", r if r
561
- f = points_to_field? label
562
- return "f", f if f
563
- return "f", label # else
564
- end
565
- def points_to_variable? (label)
566
- points_to?(label, [ "v", "var", "variable" ])
567
- end
568
- def points_to_field? (label)
569
- points_to?(label, [ "f", "field" ])
570
- end
571
- def points_to_ruby? (label)
572
- points_to?(label, [ "r", "ruby", "reval" ])
573
- end
574
- def points_to? (label, names)
575
- i = label.index(":")
576
- return nil unless i
577
- s = label[0..i-1]
578
- names.each do |name|
579
- return label[i+1..-1] if s == name
580
- end
581
- nil
582
- end
583
-
584
- class Header
585
-
586
- attr_accessor :ins, :outs
587
-
588
- def initialize
589
- @ins = []
590
- @outs = []
591
- end
592
-
593
- def add (cell, icol)
594
- if OpenWFE::starts_with(cell, "in:")
595
- @ins[icol] = cell[3..-1]
596
- #puts "i added #{@ins[icol]}"
597
- elsif OpenWFE::starts_with(cell, "out:")
598
- @outs[icol] = cell[4..-1]
599
- #puts "o added #{@outs[icol]}"
600
- end
601
- # else don't add
602
- end
603
-
604
- def to_csv
605
-
606
- s = ""
607
- @ins.each do |_in|
608
- s << "in:#{_in}," if _in
609
- end
610
- @outs.each do |out|
611
- s << "out:#{out}," if out
612
- end
613
- s[0..-2]
614
- end
615
- end
616
- end
617
-
618
- end
619
- end
620
-