<commit_before>module Jobs
  class ScheduledJob
    attr_accessor :orgunit_id, :period, :orgunit_details

    def initialize(orgunit_id:, period:, orgunit_details:)
      @orgunit_id = orgunit_id
      @period = period
      @orgunit_details = orgunit_details
    end
  end

  class ScheduledJobsService
    def initialize(project, pyramid)
      @project = project
      @pyramid = pyramid
    end

    def jobs
      Sidekiq::Queue.all.each_with_object([]) do |queue, array|
        queue.each do |job|
          next unless job.klass == "InvoiceForProjectAnchorWorker"
          next unless job.args[0].to_s == project.project_anchor_id.to_s
          orgunit_id = job.args[3].first
          array.push(
            ScheduledJob.new(
              period:          "#{job.args[1]}Q#{job.args[2]}",
              orgunit_id:      orgunit_id,
              orgunit_details: parent_names(orgunit_id)
            )
          )
        end
      end
    end

    private

    attr_reader :project, :pyramid

    def parent_names(orgunit_id)
      return nil unless pyramid
      pyramid.org_unit_parents(orgunit_id).map(&:name).join(" > ")
    end
  end
end<commit_msg>Let's reduce the cognitive complexity<commit_after>module Jobs
  class ScheduledJob
    attr_accessor :orgunit_id, :period, :orgunit_details

    def initialize(orgunit_id:, period:, orgunit_details:)
      @orgunit_id = orgunit_id
      @period = period
      @orgunit_details = orgunit_details
    end
  end

  class ScheduledJobsService
    def initialize(project, pyramid)
      @project = project
      @pyramid = pyramid
    end

    def jobs
      Sidekiq::Queue.all.each_with_object([]) do |queue, array|
        queue.each do |job|
          next unless job.klass == "InvoiceForProjectAnchorWorker"
          next unless job.args[0].to_s == project.project_anchor_id.to_s
          array.push(to_scheduled_job(job))
        end
      end
    end

    private

    attr_reader :project, :pyramid

    def to_scheduled_job(job)
      orgunit_id = job.args[3].first

      ScheduledJob.new(
        period:          "#{job.args[1]}Q#{job.args[2]}",
        orgunit_id:      orgunit_id,
        orgunit_details: parent_names(orgunit_id)
      )
    end

    def parent_names(orgunit_id)
      return nil unless pyramid
      pyramid.org_unit_parents(orgunit_id).map(&:name).join(" > ")
    end
  end
end
{'fraction_non_alphanumeric': 0.09132996632996633, 'fraction_numerical': 0.003367003367003367, 'mean_word_length': 2.43001443001443, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2129052', 'n_tokens_mistral': 784, 'n_tokens_neox': 758, 'n_words': 154}