Class: Recog::MatchReporter
- Inherits:
-
Object
- Object
- Recog::MatchReporter
- Defined in:
- lib/recog/match_reporter.rb
Instance Attribute Summary collapse
-
#fail_count ⇒ Object
readonly
Returns the value of attribute fail_count.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#line_count ⇒ Object
readonly
Returns the value of attribute line_count.
-
#match_count ⇒ Object
readonly
Returns the value of attribute match_count.
Instance Method Summary collapse
- #failure(text) ⇒ Object
- #increment_line_count ⇒ Object
-
#initialize(options, formatter) ⇒ MatchReporter
constructor
A new instance of MatchReporter.
- #match(match_data) ⇒ Object
- #print_summary ⇒ Object
- #report {|_self| ... } ⇒ Object
- #stop? ⇒ Boolean
Constructor Details
#initialize(options, formatter) ⇒ MatchReporter
Returns a new instance of MatchReporter.
8 9 10 11 12 |
# File 'lib/recog/match_reporter.rb', line 8 def initialize(, formatter) @options = @formatter = formatter reset_counts end |
Instance Attribute Details
#fail_count ⇒ Object (readonly)
Returns the value of attribute fail_count.
6 7 8 |
# File 'lib/recog/match_reporter.rb', line 6 def fail_count @fail_count end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
5 6 7 |
# File 'lib/recog/match_reporter.rb', line 5 def formatter @formatter end |
#line_count ⇒ Object (readonly)
Returns the value of attribute line_count.
6 7 8 |
# File 'lib/recog/match_reporter.rb', line 6 def line_count @line_count end |
#match_count ⇒ Object (readonly)
Returns the value of attribute match_count.
6 7 8 |
# File 'lib/recog/match_reporter.rb', line 6 def match_count @match_count end |
Instance Method Details
#failure(text) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/recog/match_reporter.rb', line 52 def failure(text) @fail_count += 1 if @options.json_format new_object = { 'data' => text, 'match_failure' => true } if @options.multi_match new_object['matches'] = nil else new_object['match'] = nil end msg = new_object.to_json else msg = "FAIL: #{text}" end formatter.("#{msg}") end |
#increment_line_count ⇒ Object
25 26 27 |
# File 'lib/recog/match_reporter.rb', line 25 def increment_line_count @line_count += 1 end |
#match(match_data) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/recog/match_reporter.rb', line 29 def match(match_data) @match_count += 1 if @options.json_format # remove data field from all matches and promote to a top-level field data_field = match_data[0]["data"] match_data.each { |h| h.delete("data") } new_object = { 'data' => data_field, } if @options.multi_match new_object['matches'] = match_data else new_object['match'] = match_data[0] end msg = new_object.to_json else match_prefix = match_data.size > 1 ? 'MATCHES' : 'MATCH' msg = "#{match_prefix}: #{match_data.map(&:inspect).join(',')}" end formatter.("#{msg}") end |
#print_summary ⇒ Object
71 72 73 |
# File 'lib/recog/match_reporter.rb', line 71 def print_summary colorize_summary(summary_line) end |
#report {|_self| ... } ⇒ Object
14 15 16 17 18 |
# File 'lib/recog/match_reporter.rb', line 14 def report reset_counts yield self summarize unless @options.quiet end |
#stop? ⇒ Boolean
20 21 22 23 |
# File 'lib/recog/match_reporter.rb', line 20 def stop? return false unless @options.fail_fast @fail_count >= @options.stop_after end |