Class: RemoteTable::Transform

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_table/transform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_tableObject

Returns the value of attribute raw_table.



3
4
5
# File 'lib/remote_table/transform.rb', line 3

def raw_table
  @raw_table
end

#rejectObject

Returns the value of attribute reject.



3
4
5
# File 'lib/remote_table/transform.rb', line 3

def reject
  @reject
end

#selectObject

Returns the value of attribute select.



3
4
5
# File 'lib/remote_table/transform.rb', line 3

def select
  @select
end

#transformObject

Returns the value of attribute transform.



3
4
5
# File 'lib/remote_table/transform.rb', line 3

def transform
  @transform
end

#transform_classObject

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_optionsObject

Returns the value of attribute transform_options.



3
4
5
# File 'lib/remote_table/transform.rb', line 3

def transform_options
  @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