<commit_before>module RSSH

  class InvalidAction < StandardError; end
  class DuplicateTag < StandardError; end
  class DuplicateHost < StandardError; end

  class Runner

    attr_accessor :action, :config

    def initialize config = nil
      @config = config || RSSH::Configuration.load
    end

    def run options
      begin
        action   = options.delete(:action)
        options  = options

        raise "No action was specified" if action.nil?

        entry = config.find action
        
        if entry
          RSSH::Connection.new( entry, options ).connect
        else
          case action
            when 'add'    then self.add RSSH::Entry.new options
            when 'list'   then self.list
            when 'remove' then self.remove options[:entry]
            else raise InvalidAction
          end    
        end
      rescue Exception => e
        puts e.message
        exit
      end
    end

    def add 
      entry = RSSH::Entry.new options

      raise "Tag already exists for '#{entry.tag}'"    if @config.has_tag?  entry.tag
      raise "Entry already exists for '#{entry.host}'" if @config.has_host? entry.host

      @config << entry
      @config.save

      msg  = "Saved '#{entry.host}'"
      msg += " with tag " + "'#{entry.tag}'" if entry.has_tag?
      puts msg
    end


    def remove 
      entry_name_or_tag = options[:entry]
      @config.remove entry_name_or_tag 
      puts "Removed entry for '#{entry_name_or_tag}'"
    end


    def list
      entries = @config.entries
      entries.each do |entry|
        puts entry.to_s
      end
    end

  end
end<commit_msg>refactored add method to accept entry param<commit_after>module RSSH

  class InvalidAction < StandardError; end
  class DuplicateTag < StandardError; end
  class DuplicateHost < StandardError; end

  class Runner

    attr_accessor :action, :config

    def initialize config = nil
      @config = config || RSSH::Configuration.load
    end

    def run options
      begin
        action   = options.delete(:action)
        options  = options

        raise "No action was specified" if action.nil?

        entry = config.find action
        
        if entry
          RSSH::Connection.new( entry, options ).connect
        else
          case action
            when 'add'    then self.add RSSH::Entry.new options
            when 'list'   then self.list
            when 'remove' then self.remove options[:entry]
            else raise InvalidAction
          end    
        end
      rescue Exception => e
        puts e.message
        exit
      end
    end

    def add entry

      if @config.has_tag?(entry.tag)
        raise DuplicateTag, "Tag already exists for '#{entry.tag}'"
      end
      if @config.has_host?(entry.host)
        raise DuplicateHost, "Host already exists for '#{entry.host}'"
      end

      @config << entry
      @config.save

      msg  = "Saved '#{entry.host}'"
      msg += " with tag " + "'#{entry.tag}'" if entry.has_tag?
      puts msg
    end


    def remove 
      entry_name_or_tag = options[:entry]
      @config.remove entry_name_or_tag 
      puts "Removed entry for '#{entry_name_or_tag}'"
    end


    def list
      entries = @config.entries
      entries.each do |entry|
        puts entry.to_s
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.08174386920980926, 'fraction_numerical': 0.0, 'mean_word_length': 1.9238938053097345, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '3555091', 'n_tokens_mistral': 967, 'n_tokens_neox': 936, 'n_words': 295}