<commit_before>require "rspec-live/example"

module RSpecLive
  class Suite
    def initialize(runner, display)
      @runner = runner
      @display = display
      @example_names = []
      @examples = {}
      @show_all = false
    end

    def toggle_all
      @show_all = !@show_all
      update_display
    end

    def inventory
      @example_names = []
      @runner.inventory do |example_data|
        update_or_create_example example_data
        update_display
      end
    end

    def update
      @runner.update do |example_data|
        update_or_create_example example_data
        update_display
      end
    end

    private

    def update_or_create_example(data)
      name = data["name"]
      @example_names << name unless @example_names.include? name
      @example_names.sort!
      @examples[name] ||= Example.new
      @examples[name].update data
      @examples[name]
    end

    def update_display
      @display.show_examples ordered_examples, summary, detailed_examples
    end

    def detailed_examples
      @show_all ? ordered_examples : ordered_examples.select(&:failed?)
    end

    def ordered_examples
      @example_names.map { |name| @examples[name] }
    end

    def summary
      passed = ordered_examples.select(&:passed?).length
      total = ordered_examples.length<commit_msg>Treat line numbers as numeric when sorting examples by name<commit_after>require "rspec-live/example"

module RSpecLive
  class Suite
    def initialize(runner, display)
      @runner = runner
      @display = display
      @example_names = []
      @examples = {}
      @show_all = false
    end

    def toggle_all
      @show_all = !@show_all
      update_display
    end

    def inventory
      @example_names = []
      @runner.inventory do |example_data|
        update_or_create_example example_data
        update_display
      end
    end

    def update
      @runner.update do |example_data|
        update_or_create_example example_data
        update_display
      end
    end

    private

    def update_or_create_example(data)
      name = data["name"]
      @example_names << name unless @example_names.include? name
      sort_example_names
      @examples[name] ||= Example.new
      @examples[name].update data
      @examples[name]
    end

    def update_display
      @display.show_examples ordered_examples, summary, detailed_examples
    end

    def detailed_examples
      @show_all ? ordered_examples : ordered_examples.select(&:failed?)
    end

    def ordered_examples
      @example_names.map { |name| @examples[name] }
    end

    def sort_example_names
      @example_names.sort_by! do |name|
        file, line = name.split(":")
        line = line.rjust(8, "0")
        [file, line].join(":")
      end
    end

    def summary
      passed = ordered_examples.select(&:passed?).length
      total = ordered_examples.length
{'fraction_non_alphanumeric': 0.0796398891966759, 'fraction_numerical': 0.0006925207756232687, 'mean_word_length': 2.5188794153471377, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 3, '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': '202554', 'n_tokens_mistral': 880, 'n_tokens_neox': 825, 'n_words': 197}