<commit_before>require "json"

module LicenseFinder
  class CocoaPods

    def self.current_packages
      podfile = YAML.load_file(lockfile_path)

      acknowledgements = JSON.parse(`plutil -convert json -o - #{Pathname.new('Pods/Pods-acknowledgements.plist').expand_path}`)["PreferenceSpecifiers"]

      podfile["PODS"].map do |pod|
        pod = pod.keys.first if pod.is_a?(Hash)

        pod_name, pod_version = pod.scan(/(.*)\s\((.*)\)/).flatten
        pod_acknowledgment = acknowledgements.detect { |hash| hash["Title"] == pod_name } || {}
        CocoaPodsPackage.new(pod_name, pod_version, pod_acknowledgment["FooterText"])
      end
    end

    def self.active?
      package_path.exist?
    end

    private

    def self.package_path
      Pathname.new("Podfile")
    end

    def self.lockfile_path
      Pathname.new("Podfile.lock")
    end

  end
end<commit_msg>Adding support for CocoaPods >= 0.34<commit_after>require "json"

module LicenseFinder
  class CocoaPods

    def self.current_packages
      podfile = YAML.load_file(lockfile_path)

      acknowledgements = JSON.parse(`plutil -convert json -o - '#{acknowledgements_path.expand_path}'`)["PreferenceSpecifiers"]

      podfile["PODS"].map do |pod|
        pod = pod.keys.first if pod.is_a?(Hash)

        pod_name, pod_version = pod.scan(/(.*)\s\((.*)\)/).flatten
        pod_acknowledgment = acknowledgements.detect { |hash| hash["Title"] == pod_name } || {}
        CocoaPodsPackage.new(pod_name, pod_version, pod_acknowledgment["FooterText"])
      end
    end

    def self.active?
      package_path.exist?
    end

    private

    def self.package_path
      Pathname.new("Podfile")
    end

    def self.lockfile_path
      Pathname.new("Podfile.lock")
    end

    def self.acknowledgements_path
      filename = 'Pods-acknowledgements.plist'
      directories = [
        'Pods',                          # cocoapods < 0.34
        'Pods/Target Support Files/Pods' # cocoapods >= 0.34
      ]

      directories.map { |dir| Pathname.new(File.join(dir, filename)) }.find(&:exist?)
    end
  end
end
{'fraction_non_alphanumeric': 0.12559923298178333, 'fraction_numerical': 0.004314477468839885, 'mean_word_length': 2.7807971014492754, 'pattern_counts': {'":': 0, '<': 4, '<?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': '3219662', 'n_tokens_mistral': 737, 'n_tokens_neox': 675, 'n_words': 124}