Class: RemoteTable::Transform
- Inherits:
-
Object
- Object
- RemoteTable::Transform
- Defined in:
- lib/remote_table/transform.rb
Instance Attribute Summary collapse
-
#raw_table ⇒ Object
Returns the value of attribute raw_table.
-
#reject ⇒ Object
Returns the value of attribute reject.
-
#select ⇒ Object
Returns the value of attribute select.
-
#transform ⇒ Object
Returns the value of attribute transform.
-
#transform_class ⇒ Object
Returns the value of attribute transform_class.
-
#transform_options ⇒ Object
Returns the value of attribute transform_options.
Instance Method Summary collapse
- #apply(raw_table) ⇒ Object
- #each_row(&block) ⇒ Object
-
#initialize(bus) ⇒ Transform
constructor
A new instance of Transform.
Constructor Details
#initialize(bus) ⇒ Transform
Returns a new instance of Transform.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/remote_table/transform.rb', line 5 def initialize(bus) if transform_params = bus.delete(:transform) @transform_class = transform_params.delete(:class) @transform_options = transform_params @transform = @transform_class.new(@transform_options) @transform.add_hints!(bus) end @select = bus[:select] @reject = bus[:reject] end |
Instance Attribute Details
#raw_table ⇒ Object
Returns the value of attribute raw_table.
3 4 5 |
# File 'lib/remote_table/transform.rb', line 3 def raw_table @raw_table end |
#reject ⇒ Object
Returns the value of attribute reject.
3 4 5 |
# File 'lib/remote_table/transform.rb', line 3 def reject @reject end |
#select ⇒ Object
Returns the value of attribute select.
3 4 5 |
# File 'lib/remote_table/transform.rb', line 3 def select @select end |
#transform ⇒ Object
Returns the value of attribute transform.
3 4 5 |
# File 'lib/remote_table/transform.rb', line 3 def transform @transform end |
#transform_class ⇒ Object
Returns the value of attribute transform_class.
3 4 5 |
# File 'lib/remote_table/transform.rb', line 3 def transform_class @transform_class end |
#transform_options ⇒ Object
Returns the value of attribute transform_options.
3 4 5 |
# File 'lib/remote_table/transform.rb', line 3 def @transform_options end |
Instance Method Details
#apply(raw_table) ⇒ Object
16 17 18 19 |
# File 'lib/remote_table/transform.rb', line 16 def apply(raw_table) self.raw_table = raw_table self end |
#each_row(&block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/remote_table/transform.rb', line 21 def each_row(&block) raw_table.each_row do |row| virtual_rows = transform ? transform.apply(row) : row # allow transform.apply(row) to return multiple rows Array.wrap(virtual_rows).each do |virtual_row| next if select and !select.call(virtual_row) next if reject and reject.call(virtual_row) yield virtual_row end end end |