<commit_before># frozen_string_literal: true

module Gemdiff
  class BundleInspector
    def list
      @list ||= outdated.split("\n").map { |line| new_outdated_gem(line) }.compact
    end

    def outdated
      @outdated ||= bundle_outdated_strict
    end

    def get(gem_name)
      list.detect { |gem| gem.name == gem_name }
    end

    private

    def bundle_outdated_strict
      `bundle outdated --strict`
    end

    def new_outdated_gem(line)
      return unless line.start_with?("  * ")

      # clean & convert new & old output to same format
      items = line.gsub("*", "")
                  .gsub("(newest", "")
                  .gsub(", installed", " >")
                  .gsub(/([(),])/, "")
                  .split(" ")

      # ["haml", "4.0.5", ">", "4.0.4"]
      # ["a_forked_gem", "0.7.0", "99ddbc9", ">", "0.7.0", "1da2295"]

      return if items[3] == ">" # skip non-gems for now
      OutdatedGem.new(items[0], items[3], items[1])<commit_msg>Split line for clarity<commit_after># frozen_string_literal: true

module Gemdiff
  class BundleInspector
    def list
      @list ||=
        outdated
          .split("\n")
          .map { |line| new_outdated_gem(line) }
          .compact
    end

    def outdated
      @outdated ||= bundle_outdated_strict
    end

    def get(gem_name)
      list.detect { |gem| gem.name == gem_name }
    end

    private

    def bundle_outdated_strict
      `bundle outdated --strict`
    end

    def new_outdated_gem(line)
      return unless line.start_with?("  * ")

      # clean & convert new & old output to same format
      items = line.gsub("*", "")
                  .gsub("(newest", "")
                  .gsub(", installed", " >")
                  .gsub(/([(),])/, "")
                  .split(" ")

      # ["haml", "4.0.5", ">", "4.0.4"]
      # ["a_forked_gem", "0.7.0", "99ddbc9", ">", "0.7.0", "1da2295"]

      return if items[3] == ">" # skip non-gems for now
      OutdatedGem.new(items[0], items[3], items[1])
{'fraction_non_alphanumeric': 0.166, 'fraction_numerical': 0.024, 'mean_word_length': 1.9910313901345291, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2112579', 'n_tokens_mistral': 709, 'n_tokens_neox': 671, 'n_words': 148}