Class: IngestionEngine::Reporter
- Inherits:
-
Object
- Object
- IngestionEngine::Reporter
- Defined in:
- lib/ingestion_engine/reporter.rb
Instance Attribute Summary collapse
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(entities, headers) ⇒ Reporter
constructor
A new instance of Reporter.
- #log(&block) ⇒ Object
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
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
3 4 5 |
# File 'lib/ingestion_engine/reporter.rb', line 3 def entities @entities end |
#headers ⇒ Object (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 |