<commit_before>module TicketMaster::Provider
  module Bugzilla
    # Project class for ticketmaster-bugzilla
    # 
    class Project < TicketMaster::Provider::Base::Project
      # declare needed overloaded methods here
      PRODUCT_API = Rubyzilla::Product
      
      # TODO: Add created_at and updated_at 
      def initialize(*object)
        if object.first
          object = object.first
          unless object.is_a? Hash
            @system_data = {:client => object}
            hash = {:id => object.id,
                    :name => object.name,
                    :description => object.name, 
                    :created_at => nil, 
                    :updated_at => nil}
          else
            hash = object
          end
          super(hash)
        end
      end
      
      # copy from this.copy(that) copies that into this
      def copy(project)
        project.tickets.each do |ticket|
          copy_ticket = self.ticket!(:title => ticket.title, :description => ticket.description)
          ticket.comments.each do |comment|
            copy_ticket.comment!(:body => comment.body)
            sleep 1
          end
        end
      end

      def self.find_by_id(id)
        self.new PRODUCT_API.new id
      end

      def self.find_by_attributes(*options)
        options = options.first
        if options.is_a? Hash
          self.find_all.select do |project|
            options.inject(true) do |memo, kv|
              break unless memo
              key, value = kv
              begin
                memo &= project.send(key) == value
              rescue NoMethodError
                memo = false
              end
              memo
            end
          end
        else 
          self.find_all.select do |project|
            options.any? { |id| project.id == id }
          end
        end
      end

      def self.find_all(*options)
        PRODUCT_API.list.collect { |product| self.new product }
      end

      def tickets(*options)
        TicketMaster::Provider::Bugzilla::Ticket.find(self.id, options)
      end

      def ticket(*options)
        TicketMaster::Provider::Bugzilla::Ticket.find_by_id(options.first)
      end

      def ticket!(*options)
        TicketMaster::Provider::Bugzilla::Ticket.create(self.id,*options)
      end

    end
  end
end
<commit_msg>refactor find_by_attributes to use search_by_attribute helper method<commit_after>module TicketMaster::Provider
  module Bugzilla
    # Project class for ticketmaster-bugzilla
    # 
    class Project < TicketMaster::Provider::Base::Project
      # declare needed overloaded methods here
      PRODUCT_API = Rubyzilla::Product
      
      # TODO: Add created_at and updated_at 
      def initialize(*object)
        if object.first
          object = object.first
          unless object.is_a? Hash
            @system_data = {:client => object}
            hash = {:id => object.id,
                    :name => object.name,
                    :description => object.name, 
                    :created_at => nil, 
                    :updated_at => nil}
          else
            hash = object
          end
          super(hash)
        end
      end
      
      # copy from this.copy(that) copies that into this
      def copy(project)
        project.tickets.each do |ticket|
          copy_ticket = self.ticket!(:title => ticket.title, :description => ticket.description)
          ticket.comments.each do |comment|
            copy_ticket.comment!(:body => comment.body)
            sleep 1
          end
        end
      end

      def self.find_by_id(id)
        self.new PRODUCT_API.new id
      end

      def self.find_by_attributes(*options)
        options = options.first
        if options.is_a? Hash
          search_by_attribute(self.find_all, options)
        else 
          self.find_all.select do |project|
            options.any? { |id| project.id == id }
          end
        end
      end

      def self.find_all(*options)
        PRODUCT_API.list.collect { |product| self.new product }
      end

      def tickets(*options)
        TicketMaster::Provider::Bugzilla::Ticket.find(self.id, options)
      end

      def ticket(*options)
        TicketMaster::Provider::Bugzilla::Ticket.find_by_id(options.first)
      end

      def ticket!(*options)
        TicketMaster::Provider::Bugzilla::Ticket.create(self.id,*options)
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.0869171570846537, 'fraction_numerical': 0.0004526935264825713, 'mean_word_length': 1.696156192800488, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2723621', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1179, 'n_words': 287}