Sha256: 0232e9573c69904b26f9316a1ffbcdda88c5353958a4d37cd7117761db2acee8

Contents?: true

Size: 1.28 KB

Versions: 46

Compression:

Stored size: 1.28 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
  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

46 entries across 46 versions & 1 rubygems

Version Path
recog-2.0.14 lib/recog/match_reporter.rb
recog-2.0.13 lib/recog/match_reporter.rb
recog-2.0.12 lib/recog/match_reporter.rb
recog-2.0.11 lib/recog/match_reporter.rb
recog-2.0.10 lib/recog/match_reporter.rb
recog-2.0.9 lib/recog/match_reporter.rb
recog-2.0.8 lib/recog/match_reporter.rb
recog-2.0.7 lib/recog/match_reporter.rb
recog-2.0.6 lib/recog/match_reporter.rb
recog-2.0.5 lib/recog/match_reporter.rb
recog-2.0.4 lib/recog/match_reporter.rb
recog-2.0.2 lib/recog/match_reporter.rb
recog-2.0.1 lib/recog/match_reporter.rb
recog-2.0.0 lib/recog/match_reporter.rb
recog-1.0.29 lib/recog/match_reporter.rb
recog-1.0.28 lib/recog/match_reporter.rb
recog-1.0.27 lib/recog/match_reporter.rb
recog-1.0.26 lib/recog/match_reporter.rb
recog-1.0.25 lib/recog/match_reporter.rb
recog-1.0.24 lib/recog/match_reporter.rb