Class: Chicago::ETL::ArraySink

Inherits:
Sink show all
Defined in:
lib/chicago/etl/array_sink.rb

Overview

An endpoint that stores rows in an Array.

Instance Attribute Summary collapse

Attributes inherited from PipelineEndpoint

#fields

Instance Method Summary collapse

Methods inherited from Sink

#close, #constant_values, #open, #set_constant_values

Methods inherited from PipelineEndpoint

#has_defined_fields?

Constructor Details

#initialize(name, fields = []) ⇒ ArraySink

Creates an ArraySink.

Optionally you may pass an array of column names if you wish to use static validation that the correct columns are written through the pipeline.



18
19
20
21
22
# File 'lib/chicago/etl/array_sink.rb', line 18

def initialize(name, fields=[])
  @name = name
  @fields = [fields].flatten
  @data = []
end

Instance Attribute Details

#dataObject (readonly)

Returns the array of written rows.



8
9
10
# File 'lib/chicago/etl/array_sink.rb', line 8

def data
  @data
end

#nameObject (readonly)

The name of this sink



11
12
13
# File 'lib/chicago/etl/array_sink.rb', line 11

def name
  @name
end

Instance Method Details

#<<(row) ⇒ Object

See Sink#<<



25
26
27
# File 'lib/chicago/etl/array_sink.rb', line 25

def <<(row)
  @data << row.merge(constant_values)
end

#truncateObject

See Sink#truncate



30
31
32
# File 'lib/chicago/etl/array_sink.rb', line 30

def truncate
  @data.clear
end