|
15 | 15 | java_import org.knime.core.data.container.BlobSupportDataRow |
16 | 16 | java_import org.knime.core.data.DataCell |
17 | 17 |
|
| 18 | +java_import org.knime.core.node.workflow.FlowVariable |
| 19 | + |
18 | 20 | # This module contains utility methods and classes |
19 | 21 | # for convinient Ruby script writing for KNIME |
20 | 22 | # See also https://tech.knime.org/javadoc-api |
@@ -55,7 +57,7 @@ def add_cell(cell) |
55 | 57 | add_cell rb_cls.new(val) |
56 | 58 | self |
57 | 59 | end |
58 | | - end |
| 60 | + end |
59 | 61 | end |
60 | 62 |
|
61 | 63 | # Instances of this class are intended for a columns container. |
@@ -120,14 +122,42 @@ def [](idx) |
120 | 122 | end |
121 | 123 | end |
122 | 124 |
|
| 125 | + # utility class for access to flow variables |
| 126 | + class FlowVariableList |
| 127 | + def self.[](name) |
| 128 | + @vars ||= $node.getAvailableFlowVariables |
| 129 | + if (flowvar = @vars[name]) |
| 130 | + case flowvar.getType |
| 131 | + when FlowVariable::Type::DOUBLE |
| 132 | + flowvar.getDoubleValue |
| 133 | + when FlowVariable::Type::INTEGER |
| 134 | + flowvar.getIntValue |
| 135 | + when FlowVariable::Type::STRING |
| 136 | + flowvar.getStringValue |
| 137 | + end |
| 138 | + end |
| 139 | + end |
| 140 | + |
| 141 | + def self.[]=(name, val) |
| 142 | + case val.class |
| 143 | + when Integer |
| 144 | + $node.pushFlowVariableInteger(name, val) |
| 145 | + when Float |
| 146 | + $node.pushFlowVariableDouble(name, val) |
| 147 | + else |
| 148 | + $node.pushFlowVariableString(name, val.to_s) |
| 149 | + end |
| 150 | + end |
| 151 | + end |
| 152 | + |
123 | 153 | def snippet_runner |
124 | 154 | count, step = $in_data_0.length, 0x2FF |
125 | 155 | coef = step / count.to_f |
126 | 156 | $in_data_0.each_with_index do |row, i| |
127 | 157 | $out_data_0 << (yield row) |
128 | 158 | setProgress "#{i * coef}%" if (i & step) == 0 |
129 | 159 | end |
130 | | - end |
| 160 | + end |
131 | 161 | end |
132 | 162 |
|
133 | 163 | include Knime |
|
0 commit comments