Class: Chicago::Flow::Transformation
- Inherits:
-
Object
- Object
- Chicago::Flow::Transformation
- Defined in:
- lib/chicago/flow/transformation.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.added_fields ⇒ Object
readonly
Returns the value of attribute added_fields.
-
.removed_fields ⇒ Object
readonly
Returns the value of attribute removed_fields.
Class Method Summary collapse
Instance Method Summary collapse
- #added_fields ⇒ Object
- #applies_to_stream?(target_stream) ⇒ Boolean
- #downstream_fields(fields) ⇒ Object
- #flush ⇒ Object
-
#initialize(*args) ⇒ Transformation
constructor
A new instance of Transformation.
- #output_streams ⇒ Object
- #process(row) ⇒ Object
- #removed_fields ⇒ Object
- #upstream_fields(fields) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Transformation
Returns a new instance of Transformation.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/chicago/flow/transformation.rb', line 6 def initialize(*args) stream, = *args if stream.kind_of?(Hash) @stream = :default @options = stream else @stream = stream || :default @options = || {} end end |
Class Attribute Details
.added_fields ⇒ Object (readonly)
Returns the value of attribute added_fields.
18 19 20 |
# File 'lib/chicago/flow/transformation.rb', line 18 def added_fields @added_fields end |
.removed_fields ⇒ Object (readonly)
Returns the value of attribute removed_fields.
18 19 20 |
# File 'lib/chicago/flow/transformation.rb', line 18 def removed_fields @removed_fields end |
Class Method Details
.adds_fields(*fields) ⇒ Object
20 21 22 23 |
# File 'lib/chicago/flow/transformation.rb', line 20 def adds_fields(*fields) @added_fields ||= [] @added_fields += fields.flatten end |
.removes_fields(*fields) ⇒ Object
25 26 27 28 |
# File 'lib/chicago/flow/transformation.rb', line 25 def removes_fields(*fields) @removed_fields ||= [] @removed_fields += fields.flatten end |
Instance Method Details
#added_fields ⇒ Object
31 32 33 |
# File 'lib/chicago/flow/transformation.rb', line 31 def added_fields self.class.added_fields end |
#applies_to_stream?(target_stream) ⇒ Boolean
59 60 61 62 63 |
# File 'lib/chicago/flow/transformation.rb', line 59 def applies_to_stream?(target_stream) @stream == :all || (target_stream.nil? && @stream == :default) || target_stream == @stream end |
#downstream_fields(fields) ⇒ Object
43 44 45 |
# File 'lib/chicago/flow/transformation.rb', line 43 def downstream_fields(fields) ((fields - removed_fields) + added_fields).uniq end |
#flush ⇒ Object
51 52 53 |
# File 'lib/chicago/flow/transformation.rb', line 51 def flush [] end |
#output_streams ⇒ Object
55 56 57 |
# File 'lib/chicago/flow/transformation.rb', line 55 def output_streams [:default] end |
#process(row) ⇒ Object
47 48 49 |
# File 'lib/chicago/flow/transformation.rb', line 47 def process(row) applies_to_stream?(row[STREAM]) ? process_row(row) : row end |
#removed_fields ⇒ Object
35 36 37 |
# File 'lib/chicago/flow/transformation.rb', line 35 def removed_fields self.class.removed_fields end |
#upstream_fields(fields) ⇒ Object
39 40 41 |
# File 'lib/chicago/flow/transformation.rb', line 39 def upstream_fields(fields) ((fields + removed_fields) - added_fields).uniq end |