Sha256: aeeba2af5828fb46e0935d2827b6fb747a1ba755d53665c4d48f77e35159f466

Contents?: true

Size: 1.3 KB

Versions: 86

Compression:

Stored size: 1.3 KB

Contents

module Recog
class MatchReporter
  attr_reader :formatter
  attr_reader :line_count, :match_count, :fail_count

  def initialize(options, formatter)
    @options = options
    @formatter = formatter
    reset_counts
  end

  def report
    reset_counts
    yield self
    summarize unless @options.quiet
  end

  def stop?
    return false unless @options.fail_fast
    @fail_count >= @options.stop_after
  end

  def increment_line_count
    @line_count += 1
  end

  def match(text)
    @match_count += 1
    formatter.success_message(text)
  end

  def failure(text)
    @fail_count += 1
    formatter.failure_message(text)
  end

  def print_summary
    colorize_summary(summary_line)
  end

  private

  def reset_counts
    @line_count = @match_count = @fail_count = 0
  end

  def detail?
    @options.detail
  end

  def summarize
    if detail?
      print_lines_processed
      print_summary
    end
  end

  def print_lines_processed
    formatter.status_message("\nProcessed #{line_count} lines")
  end

  def summary_line
    summary = "SUMMARY: "
    summary << "#{match_count} matches"
    summary << " and #{fail_count} failures"
    summary
  end

  def colorize_summary(summary)
    if @fail_count > 0
      formatter.failure_message(summary)
    else
      formatter.success_message(summary)
    end
  end
end
end

Version data entries

86 entries across 86 versions & 2 rubygems

Version Path
recog-3.0.1 lib/recog/match_reporter.rb
recog-2.3.23 lib/recog/match_reporter.rb
recog-2.3.22 lib/recog/match_reporter.rb
recog-2.3.21 lib/recog/match_reporter.rb
recog-2.3.20 lib/recog/match_reporter.rb
recog-2.3.19 lib/recog/match_reporter.rb
recog-2.3.18 lib/recog/match_reporter.rb
recog-2.3.17 lib/recog/match_reporter.rb
recog-2.3.16 lib/recog/match_reporter.rb
recog-2.3.15 lib/recog/match_reporter.rb
recog-intrigue-2.3.14 lib/recog/match_reporter.rb
recog-2.3.14 lib/recog/match_reporter.rb
recog-2.3.13 lib/recog/match_reporter.rb
recog-2.3.12 lib/recog/match_reporter.rb
recog-2.3.11 lib/recog/match_reporter.rb
recog-2.3.10 lib/recog/match_reporter.rb
recog-2.3.9 lib/recog/match_reporter.rb
recog-intrigue-2.3.7 lib/recog/match_reporter.rb
recog-2.3.8 lib/recog/match_reporter.rb
recog-2.3.7 lib/recog/match_reporter.rb