Class: IngestionEngine::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/ingestion_engine/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entities, headers) ⇒ Reporter

Returns a new instance of Reporter.



5
6
7
8
# File 'lib/ingestion_engine/reporter.rb', line 5

def initialize(entities, headers)
  @entities = entities
  @headers = headers
end

Instance Attribute Details

#entitiesObject (readonly)

Returns the value of attribute entities.



3
4
5
# File 'lib/ingestion_engine/reporter.rb', line 3

def entities
  @entities
end

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/ingestion_engine/reporter.rb', line 3

def headers
  @headers
end

Instance Method Details

#log(&block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/ingestion_engine/reporter.rb', line 10

def log(&block)
  File.open('invalid.csv', 'w') do |f|
    f.puts (headers + ['errors']).join(',')
    entities.each do |entity|
      msg = yield(entity)
      values = headers.map{ |header| entity.send(header) }
      f.puts (values + [msg.gsub(/,/, '')]).join(', ')
    end
  end
end