<commit_before>module TaggingHistory
  class LinkChanges
    def initialize(params)
      @params = params
    end

    def changes
      @_changes ||= link_changes_from_publishing_api.map do |change|
        user = User.find_by_uid(change[:user_uid])

        if user.present?
          change[:user_uid] = user.uid
          change[:user_name] = user.name
          change[:organisation] = user.organisation_slug.try do |slug|
            slug.capitalize.tr('-', ' ')
          end
        end

        change
      end
    end

    def filter_by_user_options
      options = {}

      changes.each do |change|
        next unless change.key? :user_uid
        options[change[:user_name]] = change[:user_uid]
      end

      options
    end

  private

    def link_changes_from_publishing_api
      Services.link_changes_api
        .get_link_changes(
          { link_types: ['taxons'] }.merge(@params)
        )
        .to_hash
        .deep_symbolize_keys[:link_changes]
    end
  end
end<commit_msg>In LinkChanges, switch to using each_with_object<commit_after>module TaggingHistory
  class LinkChanges
    def initialize(params)
      @params = params
    end

    def changes
      @_changes ||= link_changes_from_publishing_api.map do |change|
        user = User.find_by_uid(change[:user_uid])

        if user.present?
          change[:user_uid] = user.uid
          change[:user_name] = user.name
          change[:organisation] = user.organisation_slug.try do |slug|
            slug.capitalize.tr('-', ' ')
          end
        end

        change
      end
    end

    def filter_by_user_options
      changes.each_with_object({}) do |change, options|
        next unless change.key? :user_uid
        options[change[:user_name]] = change[:user_uid]
      end
    end

  private

    def link_changes_from_publishing_api
      Services.link_changes_api
        .get_link_changes(
          { link_types: ['taxons'] }.merge(@params)
        )
        .to_hash
        .deep_symbolize_keys[:link_changes]
    end
  end
end
{'fraction_non_alphanumeric': 0.08868201861832435, 'fraction_numerical': 0.0, 'mean_word_length': 2.1856474258970358, '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': '3822843', 'n_tokens_mistral': 632, 'n_tokens_neox': 619, 'n_words': 125}