<commit_before># -*- coding: utf-8 -*-
require 'rspec/core/formatters/base_text_formatter'

class NyanCatFormatter < RSpec::Core::Formatters::BaseTextFormatter

  ESC     = "\e["
  NND     = "#{ESC}0m"
  PASS    = '='
  FAIL    = '*'
  ERROR   = '!'
  PENDING = '·'

  attr_reader :title, :current, :example_results, :color_index

  def start(example_count)
    super(example_count)
    @current, @color_index = 0,0
    @bar_length = 70
    @example_results = []
  end

  def example_passed(example)
    super(example)
    tick PASS
  end

  def example_pending(example)
    super(example)
    @pending_count =+1
    tick PENDING
  end

  def example_failed(example)
    super(example)
    @failure_count =+1
    tick FAIL
  end

  def start_dump
    @current = @example_count
  end

  def dump_summary(duration, example_count, failure_count, pending_count)
    dump_profile if profile_examples? && failure_count == 0
    summary = "\nNyan Cat flew #{format_seconds(duration)} seconds".split(//).map { |c| rainbowify(c) }
    output.puts summary.join
    output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
    dump_commands_to_rerun_failed_examples
  end

  def dump_failures
    # noop
  end

  # Increments the example count and displays the current progress
  #
  # Returns nothing
  def tick(mark = PASS)
    @example_results << mark
    @current =  (@current > @example_count) ? @example_count : @current + 1
    @title = "  #{current}/#{example_count}"
    dump_progress
  end

  # Creates a rainbow trail
  #
  # Returns the sprintf format of the Nyan cat
  def nyan_trail
    width =  percentage * @bar_length / 100
    marker = @example_results.map{ |mark| highlight(mark) }.join
    sprintf("%s#{nyan_cat}%s", marker, " " * (@bar_length - width) )
  end

  # Calculates the percentage completed any given point
  #
  # Returns Fixnum of the percentage
  def percentage
    @example_count.zero? ? 100 : @current * 100 / @example_count
  end

  # Ascii Nyan Cat. If tests are complete, Nyan Cat goes to sleep. If
  # there are failing or pending examples, Nyan Cat is concerned.
  #
  # Returns String Nyan Cat
  def nyan_cat
    if @failure_count > 0 || @pending_count > 0
      '~|_(o.o)'
    elsif (@current == @example_count)
      '~|_(-.-)'
    else
      '~|_(^.^)'
    end
  end

  # Displays the current progress in all Nyan Cat glory
  #
  def dump_progress
    max_width = 80
    line  = sprintf("%-8s %s", @title[0,(7)] + ":", nyan_trail)
    tail  = (@current == @example_count) ? "\n" : "\r"

    if line.length == max_width - 1
      output.print line + tail
      output.flush
    elsif line.length >= max_width
      @bar_length = [@bar_length - (line.length - max_width + 1), 0].max
      @bar_length == 0 ? output.print( rainbowify(line + tail) ) : dump_progress
    else
      @bar_length += max_width - line.length + 1<commit_msg>count title width and align title to right<commit_after># -*- coding: utf-8 -*-
require 'rspec/core/formatters/base_text_formatter'

class NyanCatFormatter < RSpec::Core::Formatters::BaseTextFormatter

  ESC     = "\e["
  NND     = "#{ESC}0m"
  PASS    = '='
  FAIL    = '*'
  ERROR   = '!'
  PENDING = '·'

  attr_reader :title, :current, :example_results, :color_index

  def start(example_count)
    super(example_count)
    @current, @color_index = 0,0
    @bar_length = 70
    @example_results = []
  end

  def example_passed(example)
    super(example)
    tick PASS
  end

  def example_pending(example)
    super(example)
    @pending_count =+1
    tick PENDING
  end

  def example_failed(example)
    super(example)
    @failure_count =+1
    tick FAIL
  end

  def start_dump
    @current = @example_count
  end

  def dump_summary(duration, example_count, failure_count, pending_count)
    dump_profile if profile_examples? && failure_count == 0
    summary = "\nNyan Cat flew #{format_seconds(duration)} seconds".split(//).map { |c| rainbowify(c) }
    output.puts summary.join
    output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
    dump_commands_to_rerun_failed_examples
  end

  def dump_failures
    # noop
  end

  # Increments the example count and displays the current progress
  #
  # Returns nothing
  def tick(mark = PASS)
    @example_results << mark
    @current =  (@current > @example_count) ? @example_count : @current + 1
    @title = "  #{current}/#{example_count}"
    dump_progress
  end

  # Creates a rainbow trail
  #
  # Returns the sprintf format of the Nyan cat
  def nyan_trail
    width =  percentage * @bar_length / 100
    marker = @example_results.map{ |mark| highlight(mark) }.join
    sprintf("%s#{nyan_cat}%s", marker, " " * (@bar_length - width) )
  end

  # Calculates the percentage completed any given point
  #
  # Returns Fixnum of the percentage
  def percentage
    @example_count.zero? ? 100 : @current * 100 / @example_count
  end

  # Ascii Nyan Cat. If tests are complete, Nyan Cat goes to sleep. If
  # there are failing or pending examples, Nyan Cat is concerned.
  #
  # Returns String Nyan Cat
  def nyan_cat
    if @failure_count > 0 || @pending_count > 0
      '~|_(o.o)'
    elsif (@current == @example_count)
      '~|_(-.-)'
    else
      '~|_(^.^)'
    end
  end

  # Displays the current progress in all Nyan Cat glory
  #
  def dump_progress
    title_width = @example_count.to_s.length * 2 + 4
    max_width   = 80
    line  = sprintf("%#{title_width}s %s", @title + ":", nyan_trail)
    tail  = (@current == @example_count) ? "\n" : "\r"

    if line.length == max_width - 1
      output.print line + tail
      output.flush
    elsif line.length >= max_width
      @bar_length = [@bar_length - (line.length - max_width + 1), 0].max
      @bar_length == 0 ? output.print( rainbowify(line + tail) ) : dump_progress
    else
      @bar_length += max_width - line.length + 1
{'fraction_non_alphanumeric': 0.11545655500765176, 'fraction_numerical': 0.010372385648699202, 'mean_word_length': 3.056551724137931, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6855117', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1951, 'n_words': 520}