<commit_before># @todo Go over :attr_accessor and decide on correct access. 
# @todo Review method names and determine if need '?' or '!' 
# @todo Decide if methods should return nil or self.
module GemCov
  # This class implements a Hash that uses a gem name as a key, 
  # and stores the GemCoverageEntry for that gem name.
  # The GemCoverageEntry for a gem stores the gemsets a gem is 
  # found in and the versions of the gem found in those gemset.
  #
  # Gems matching various conditions can be listed using the list_* methods.
  class GemHash < Hash
  
    # The update! method takes a gem listing line of the kind produced by 
    # the 'gem list' command and adds or updates the GemCoverageEntry 
    # for a given gem name.
    def update!(gem_listing_line,gemset)
      gem_listing = GemListing.new(gem_listing_line)
      if self.has_key? gem_listing.name
        self[gem_listing.name].add_gemset_versions(gemset,gem_listing.versions)
      else
        self[gem_listing.name] = GemCoverageEntry.new(gem_listing.name)
        self[gem_listing.name].add_gemset_versions(gemset,gem_listing.versions)
      end
      self
    end
  
    # List all gems installed across all gemsets, ordered alphabetically.
    def all_gems()
      self.sort.collect {|k,g| g }
    end
  
    # List the locations of the gems specified when using the --gems option.  
    def desired_gems(list_of_gems)
      specified_gems = []
      list_of_gems.each do |g| 
        if self.has_key? g
          specified_gems << self[g]
        else
          specified_gems <<  "'#{g}' not found in any gemset"
        end
      end

			specified_gems
    end
  
    # List all gems flagged as being found in all gemsets
    # If in 'global' gemset, exclude from listing.
    def common_gems(gemsets)                                           
      common_gems = self.each_value.find_all do |gce| 
        gce.in_all_gemsets_but_global? gemsets 
      end
    end  
  
    # List all gems found in the 'default' gemset, i.e. gems installed to 
    # the ruby instance, but not in a gemset.  
    def default_gems()                                                               
      puts "Gems found in default gem install location:"
      gems_in_default = self.each_value.find_all do |gce|
        gce.gemsets_containing.include? 'default'
      end
    end
  end
  
  # This class contains information describing which gemsets a gem 
  # is found in and what versions of the gem are installed in each gemset.
  class GemCoverageEntry
    attr_accessor :name, :gemset_versions, :gemsets_containing
    # Requires a gem name and initializes instance variables.
    def initialize(name)
      @name = name
      @gemset_versions = {}
      @gemsets_containing = []
    end
  
    # Given a gemset name and an Array of installed versions, 
    # adds this to the GemCoverageEntry.
    def add_gemset_versions(gemset,versions)
      @gemset_versions[gemset] = versions
      @gemsets_containing << gemset <commit_msg>Refactored RDoc for old list_* methods<commit_after># @todo Go over :attr_accessor and decide on correct access. 
# @todo Review method names and determine if need '?' or '!' 
# @todo Decide if methods should return nil or self.
module GemCov
  # This class implements a Hash that uses a gem name as a key, 
  # and stores the GemCoverageEntry for that gem name.
  # The GemCoverageEntry for a gem stores the gemsets a gem is 
  # found in and the versions of the gem found in those gemset.
  #
  # Gems matching various conditions can be listed using the list_* methods.
  class GemHash < Hash
  
    # The update! method takes a gem listing line of the kind produced by 
    # the 'gem list' command and adds or updates the GemCoverageEntry 
    # for a given gem name.
    def update!(gem_listing_line,gemset)
      gem_listing = GemListing.new(gem_listing_line)
      if self.has_key? gem_listing.name
        self[gem_listing.name].add_gemset_versions(gemset,gem_listing.versions)
      else
        self[gem_listing.name] = GemCoverageEntry.new(gem_listing.name)
        self[gem_listing.name].add_gemset_versions(gemset,gem_listing.versions)
      end
      self
    end
  
    # Returns a list of all gems installed across all gemsets, ordered alphabetically.
    def all_gems()
      self.sort.collect {|k,g| g }
    end
  
    # Returns a list of the locations of the gems specified when using the --gems option.  
    def desired_gems(list_of_gems)
      specified_gems = []
      list_of_gems.each do |g| 
        if self.has_key? g
          specified_gems << self[g]
        else
          specified_gems <<  "'#{g}' not found in any gemset"
        end
      end

			specified_gems
    end
  
    # Returns a list of all gems flagged as being found in all gemsets
    # If in 'global' gemset, exclude from listing.
    def common_gems(gemsets)                                           
      common_gems = self.each_value.find_all do |gce| 
        gce.in_all_gemsets_but_global? gemsets 
      end
    end  
  
    # Returns a list of all gems found in the 'default' gemset, i.e. gems installed to 
    # the ruby instance, but not in a gemset.  
    def default_gems()                                                               
      puts "Gems found in default gem install location:"
      gems_in_default = self.each_value.find_all do |gce|
        gce.gemsets_containing.include? 'default'
      end
    end
  end
  
  # This class contains information describing which gemsets a gem 
  # is found in and what versions of the gem are installed in each gemset.
  class GemCoverageEntry
    attr_accessor :name, :gemset_versions, :gemsets_containing
    # Requires a gem name and initializes instance variables.
    def initialize(name)
      @name = name
      @gemset_versions = {}
      @gemsets_containing = []
    end
  
    # Given a gemset name and an Array of installed versions, 
    # adds this to the GemCoverageEntry.
    def add_gemset_versions(gemset,versions)
      @gemset_versions[gemset] = versions
      @gemsets_containing << gemset 
{'fraction_non_alphanumeric': 0.06139917695473251, 'fraction_numerical': 0.0, 'mean_word_length': 2.4680365296803655, 'pattern_counts': {'":': 0, '<': 17, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2073849', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1742, 'n_words': 641}