Class: Threatinator::Actions::Run::CoverageObserver
- Inherits:
-
Object
- Object
- Threatinator::Actions::Run::CoverageObserver
- Defined in:
- lib/threatinator/actions/run/coverage_observer.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(filename) ⇒ CoverageObserver
constructor
A new instance of CoverageObserver.
- #log_record(status, record, event_count, message = '') ⇒ Object
- #open ⇒ Object
-
#update(message, *args) ⇒ Object
Handles FeedRunner observations.
Constructor Details
#initialize(filename) ⇒ CoverageObserver
Returns a new instance of CoverageObserver.
8 9 10 11 |
# File 'lib/threatinator/actions/run/coverage_observer.rb', line 8 def initialize(filename) @filename = filename @csv = nil end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/threatinator/actions/run/coverage_observer.rb', line 7 def filename @filename end |
Instance Method Details
#close ⇒ Object
53 54 55 |
# File 'lib/threatinator/actions/run/coverage_observer.rb', line 53 def close @csv.close unless closed? end |
#closed? ⇒ Boolean
13 14 15 16 |
# File 'lib/threatinator/actions/run/coverage_observer.rb', line 13 def closed? return false if @csv.nil? @csv.closed? end |
#log_record(status, record, event_count, message = '') ⇒ Object
46 47 48 49 50 51 |
# File 'lib/threatinator/actions/run/coverage_observer.rb', line 46 def log_record(status, record, event_count, = '') return if closed? @csv.add_row( [ status, event_count, record.line_number, record.pos_start, record.pos_end, record.data.inspect, ]) end |
#open ⇒ Object
18 19 20 |
# File 'lib/threatinator/actions/run/coverage_observer.rb', line 18 def open @csv = ::CSV.open(@filename, "wb", :headers => [:status, :event_count, :line_number, :pos_start, :pos_end, :data, :message], :write_headers => true) end |
#update(message, *args) ⇒ Object
Handles FeedRunner observations
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/threatinator/actions/run/coverage_observer.rb', line 23 def update(, *args) case when :record_missed log_record(:missed, args.shift, 0) when :record_filtered log_record(:filtered, args.shift, 0) when :record_parsed log_record(:parsed, args.shift, args.shift.count) when :record_error record = args.shift errors = args.shift = errors.map { |e| e. }.join(', ') log_record(:error, record, 0, ) when :end close when :start open end end |