<commit_before># Front for RubyGems
class SourceUnavailableError < StandardError; end
class RubyGemReader
  attr_reader :uri
  
  def initialize(uri)
    @connection = nil
    @uri = uri #.gsub('https://', 'http://') # No SSL for the moment
    # puts @uri.inspect
    # puts @uri.scheme
  end
  
  # May raise SourceUnavailableError if the source can't be accessed
  def get(path, data={}, content_type='application/x-www-form-urlencoded')
    begin
      request = Net::HTTP::Get.new(path)
      request.add_field 'Connection', 'keep-alive'
      request.add_field 'Keep-Alive', '30'
      request.add_field 'User-Agent', 'github.com/jonathannen/gemfresh'
      response = connection.request request
      response.body  
    rescue StandardError => se
      # For now we assume this is an unavailable repo
      raise SourceUnavailableError.new(se.message)
    end
  end
  
  private
  # A persistent connection
  def connection(host = Gem.host)
    return @connection unless @connection.nil?
    @connection = Net::HTTP.new self.uri.host, self.uri.port
    @connection.start    
    @connection
  end
end


# A class to encapsulate the difference between gem states
class SpecDiff < Struct.new(:dep, :spec, :gemdata, :versions)
  
  # Configure the diff
  def initialize(*args)
    super
    # Check for prerelease - Gem rules are that a letter indicates a prerelease
    # See http://rubygems.rubyforge.org/rubygems-update/Gem/Version.html#method-i-prerelease-3F
    @prerelease = version_in_use =~ /[a-zA-Z]/
  end
  
  # Return a :month1, :month6, :year1, :more depending on the
  # build age of the available version
  def build_age
    build_date = version_build_date(version_in_use)
    return :none if build_date.nil?
    days = ((Time.now.utc - build_date)/(24 * 60 * 60)).round
    case
    when days < 31  then :month1<commit_msg>Removed unnecessary reference to Gem.host<commit_after># Front for RubyGems
class SourceUnavailableError < StandardError; end
class RubyGemReader
  attr_reader :uri
  
  def initialize(uri)
    @connection = nil
    @uri = uri #.gsub('https://', 'http://') # No SSL for the moment
    # puts @uri.inspect
    # puts @uri.scheme
  end
  
  # May raise SourceUnavailableError if the source can't be accessed
  def get(path, data={}, content_type='application/x-www-form-urlencoded')
    begin
      request = Net::HTTP::Get.new(path)
      request.add_field 'Connection', 'keep-alive'
      request.add_field 'Keep-Alive', '30'
      request.add_field 'User-Agent', 'github.com/jonathannen/gemfresh'
      response = connection.request request
      response.body  
    rescue StandardError => se
      # For now we assume this is an unavailable repo
      raise SourceUnavailableError.new(se.message)
    end
  end
  
  private
  # A persistent connection
  def connection
    return @connection unless @connection.nil?
    @connection = Net::HTTP.new self.uri.host, self.uri.port
    @connection.start    
    @connection
  end
end


# A class to encapsulate the difference between gem states
class SpecDiff < Struct.new(:dep, :spec, :gemdata, :versions)
  
  # Configure the diff
  def initialize(*args)
    super
    # Check for prerelease - Gem rules are that a letter indicates a prerelease
    # See http://rubygems.rubyforge.org/rubygems-update/Gem/Version.html#method-i-prerelease-3F
    @prerelease = version_in_use =~ /[a-zA-Z]/
  end
  
  # Return a :month1, :month6, :year1, :more depending on the
  # build age of the available version
  def build_age
    build_date = version_build_date(version_in_use)
    return :none if build_date.nil?
    days = ((Time.now.utc - build_date)/(24 * 60 * 60)).round
    case
    when days < 31  then :month1
{'fraction_non_alphanumeric': 0.10137875101378752, 'fraction_numerical': 0.008110300081103, 'mean_word_length': 3.218928164196123, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4346060', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1152, 'n_words': 336}