Class: Pipeline::Parser::CSVParser

Inherits:
Base
  • Object
show all
Defined in:
lib/etl-pipeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCSVParser

Returns a new instance of CSVParser.



12
13
14
15
# File 'lib/etl-pipeline.rb', line 12

def initialize
  @attribute_matrix = Hash.new
  @items            = Array.new
end

Instance Attribute Details

#attribute_matrixObject

Returns the value of attribute attribute_matrix.



11
12
13
# File 'lib/etl-pipeline.rb', line 11

def attribute_matrix
  @attribute_matrix
end

#itemsObject

Returns the value of attribute items.



11
12
13
# File 'lib/etl-pipeline.rb', line 11

def items
  @items
end

#modelObject

Returns the value of attribute model.



11
12
13
# File 'lib/etl-pipeline.rb', line 11

def model
  @model
end

Instance Method Details

#coerce(input, output) ⇒ Object



17
18
19
20
# File 'lib/etl-pipeline.rb', line 17

def coerce(input, output)
  @attribute_matrix.each do |attr, prok|
  end
end

#match(attribute, prok) ⇒ Object



34
35
36
# File 'lib/etl-pipeline.rb', line 34

def match(attribute, prok)
  @attribute_matrix[attribute.to_sym] = prok
end

#parse(file_path, options = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/etl-pipeline.rb', line 22

def parse(file_path, options={})
  CSV.foreach(file_path, options) do |csv|
    obj = @model.new
    coerce csv, obj
    yield csv
  end
end

#register_model(model) ⇒ Object



30
31
32
# File 'lib/etl-pipeline.rb', line 30

def register_model(model)
  self.model = model
end