<commit_before>class Bundle
  
  BUNDLE = "config/extensions.yml"
  
  #
  # Generates a bundle file with the submodule configuration
  #   +project+ the project to install its bundle
  #   +options+ the command line options
  #
  def self.generate(project, options)
    File.open(project.root + BUNDLE, 'w') do |file| 
      file.write("---\n")
      project.extensions.each do |extension|
        
        puts "***".blue + "Process extension ".dark_green + "'#{extension.to_s}'".yellow if options.verbose?
        
        file.write("- name: #{extension.to_s}\n")
        file.write("  hub: #{hub(extension.remotes['origin'])}\n")
        
        if options.remotes?
          extension.remotes.each do |name, url|
            remote = hub(url, true)
            file.write("  - remote: #{remote}\n") if name != 'origin'
            puts "  - Remote".white + "'#{remote}'".cyan + "registered".white if options.verbose?
          end
        end
      
      end
      
      puts "Bundle written to " + BUNDLE
    end
    
  end
  
  #
  # Installs the submodules from the bundle
  #   +project+ the project to install its bundle
  #   +options+ the command line options
  #
  def self.install(project, options)
    puts "Not yet implemented"
    exit 1
  end
  
  private
  
    #
    # Gets the hub from the repositories url
    #   +url+ the url to the extensions repository
    #
    def self.hub(url, remote = false)
      if url =~ /git(@|:\/\/)github.com(:|\/)([a-zA-z0-9_\-]+)\/([a-zA-z0-9_\-]+).git/
        if remote
          return Regexp.last_match(3) + '/' + Regexp.last_match(4)
        else
          return Regexp.last_match(3)
        end
      else
        return url
      end
    end
  
end<commit_msg>Writing now correct bundles. First parsing for the installation process (not yet done).<commit_after>class Bundle
  
  BUNDLE = "config/extensions.yml"
  
  #
  # Generates a bundle file with the submodule configuration
  #   +project+ the project to install its bundle
  #   +options+ the command line options
  #
  def self.generate(project, options)
    File.open(project.root + BUNDLE, 'w') do |file| 
      file.write("---\n")
      project.extensions.each do |extension|
        
        file.write("- name: #{extension.to_s}\n")
        file.write("  hub: #{hub(extension.to_s, extension.remotes['origin'])}\n")

        extension.remotes.delete('origin')
        
        if options.remotes?
          file.write("  remotes:\n")
          extension.remotes.each do |name, url|
            remote = hub(extension.to_s, url, true)
            file.write("    - #{remote}\n")
          end
        end
      
      end
      
      puts "Bundle written to " + BUNDLE
    end

    File.open(project.root + BUNDLE).each { |line| puts line } if options.verbose?
  end
  
  #
  # Installs the submodules from the bundle
  #   +project+ the project to install its bundle
  #   +options+ the command line options
  #
  def self.install(project, options)
    bundle = YAML::load_file(project.root + BUNDLE)
    bundle.each do |extension|
      name = extension['name']
      if not project.extensions.map{|e| e.to_s }.include?(name)
        puts "TODO: Installing" + name
      end
      if extension['remotes']
        extension['remotes'].each do |remote|
          Dir.chdir(project.root + "vendor/extensions" + name) do
            puts "TODO: Register " + remote
          end
        end
      end
    end
  end
  
  private
  
    #
    # Gets the hub from the repositories url
    #   +name+ name of the extension
    #   +url+ the url to the extensions repository
    #   +remote+ true if remote
    #
    def self.hub(name, url, remote = false)
      if url =~ /git(@|:\/\/)github.com(:|\/)([a-zA-z0-9_\-]+)\/([a-zA-z0-9_\-]+).git/
        if remote and not known_format?(Regexp.last_match(4), name)
          return Regexp.last_match(3) + '/' + Regexp.last_match(4)
        else
          return Regexp.last_match(3)
        end
      else
        return url
      end
    end

    #
    # Is the format of the radiant extension naming known?
    #   +full_name+ full name of the extension, eg. radiant-comments-extension
    #   +name+ name of the extension, e.g. comments
    #
    def self.known_format?(full_name, name)
      decline_radiant_extension(name).include?(full_name)
    end

    #
    # Returns an array of known radiant extension naming variants
    #   +name+ name of the extension
    #
    def self.decline_radiant_extension(name)
       [
         "radiant-#{name}-extension",
         "radiant-#{name.to_s.gsub('_','-')}-extension",
         "radinat-#{name}",
         "radiant-#{name.to_s.gsub('_','-')}",
         "#{name}",
         "#{name}.gsub('_','-')",
         "radiant_#{name}_extension",
         "radiant_#{name.to_s.gsub('_','-')}_extension",
         "radinat_#{name}",
         "radiant_#{name.to_s.gsub('_','-')}",
       ]
    end
end
{'fraction_non_alphanumeric': 0.13418855630217877, 'fraction_numerical': 0.003257992262268377, 'mean_word_length': 2.0990536277602523, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4782884', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1592, 'n_words': 396}