Class: Ibex::Coverage::Collector
- Inherits:
-
Object
- Object
- Ibex::Coverage::Collector
- Defined in:
- lib/ibex/coverage/collector.rb
Overview
Strictly turns one or more complete parse sessions into a coverage report.
Class Method Summary collapse
Instance Method Summary collapse
- #consume(document, source:, line:) ⇒ Object
- #finish(source:) ⇒ Object
-
#initialize ⇒ Collector
constructor
A new instance of Collector.
Constructor Details
#initialize ⇒ Collector
Returns a new instance of Collector.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ibex/coverage/collector.rb', line 20 def initialize @grammar_digest = nil @table_format_version = nil @state_count = nil @production_count = nil @sessions = 0 @event_count = 0 @state_hits = Hash.new(0) @production_hits = Hash.new(0) @in_session = false @expected_sequence = 1 end |
Class Method Details
.collect_file(path) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ibex/coverage/collector.rb', line 34 def self.collect_file(path) collector = new EventStream.each_file(path) do |document, line| collector.consume(document, source: path, line: line) end collector.finish(source: path) end |
Instance Method Details
#consume(document, source:, line:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ibex/coverage/collector.rb', line 43 def consume(document, source:, line:) event = document.fetch("event") sequence = document.fetch("sequence") if event == "start" start_session(document.fetch("data"), sequence, source, line) else consume_session_event(event, document.fetch("data"), sequence, source, line) end @event_count += 1 end |
#finish(source:) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ibex/coverage/collector.rb', line 55 def finish(source:) invalid(source, 1, "event stream ended before accept or reject") if @in_session invalid(source, 1, "event stream does not contain a parse session") if @sessions.zero? Report.new( grammar_digest: (@grammar_digest), table_format_version: (@table_format_version), state_count: (@state_count), production_count: (@production_count), sessions: @sessions, event_count: @event_count, state_hits: @state_hits, production_hits: @production_hits ) rescue ArgumentError => e raise Ibex::Error, "#{source}:1:1: #{e.}" end |