Sha256: 1a1d315ab6653ee6cde7506d14f0361c991e6e44311fdac66be3204116ccf578

Contents?: true

Size: 1.75 KB

Versions: 44

Compression:

Stored size: 1.75 KB

Contents

module Recog
class VerifyReporter
  attr_reader :formatter
  attr_reader :success_count, :warning_count, :failure_count

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

  def report(fingerprint_count)
    reset_counts
    yield self
    summarize(fingerprint_count)
  end

  def success(text)
    @success_count += 1
    formatter.success_message("#{padding}#{text}") if detail?
  end

  def warning(text)
    @warning_count += 1
    formatter.warning_message("#{padding}#{text}")
  end

  def failure(text)
    @failure_count += 1
    formatter.failure_message("#{padding}#{text}")
  end

  def print_name(fingerprint)
    if detail? && fingerprint.tests.any?
      name = fingerprint.name.empty? ? '[unnamed]' : fingerprint.name
      formatter.status_message("\n#{name}")
    end
  end

  def summarize(fingerprint_count)
    print_fingerprint_count(fingerprint_count) if detail?
    print_summary
  end

  def print_fingerprint_count(count)
    formatter.status_message("\nVerified #{count} fingerprints:")
  end

  def print_summary
    colorize_summary(summary_line)
  end

  private

  def reset_counts
    @success_count = @failure_count = @warning_count = 0
  end

  def detail?
    @options.detail
  end

  def padding
    '   ' if @options.detail
  end

  def summary_line
    summary = "SUMMARY: Test completed with "
    summary << "#{@success_count} successful"
    summary << ", #{@warning_count} warnings"
    summary << ", and #{@failure_count} failures"
    summary
  end

  def colorize_summary(summary)
    if @failure_count > 0
      formatter.failure_message(summary)
    elsif @warning_count > 0
      formatter.warning_message(summary)
    else
      formatter.success_message(summary)
    end
  end
end
end

Version data entries

44 entries across 44 versions & 1 rubygems

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