<commit_before>require 'xcodeproj'
require 'semantic'
require 'find'

module Timewizard
  module Versioner
    class Apple
      attr_accessor :dir
      attr_reader :proj
      attr_reader :plists
      attr_reader :old_bundle_version
      attr_reader :old_build_number
      attr_accessor :new_bundle_version
      attr_accessor :new_build_number

      def initialize(dir)
        @dir = dir
        @proj = nil
        @plists = []
      end

      def find_xcode_project()
        if File.directory?(@dir)
          # check if the directory exists
          unless Dir.exist?(@dir)
            raise "directory passed in does not exist"
          end
          temp_file = nil
          # check if the directory contains a .xcodeproj
          Dir.foreach(@dir.to_s) { |x|
            if x.end_with?(".xcodeproj")
              temp_file = x
            end }
          if temp_file.nil?
            raise "there is no .xcodeproj in the given directory"
          end
          @proj = File.expand_path(temp_file, @dir)
        else
          unless File.exist?(@dir)
            raise "file passed in does not exist"
          end
          unless @dir.end_with?(".xcodeproj")
            raise "file must be a .xcodeproj"
          end
          temp_file = File.absolute_path(@dir)
          @proj = temp_file
        end
      end

      def find_plists()
        if @proj.nil?
          raise "there is no .xcodeproj"
        end
        directory = File.dirname(@proj.to_s)
        unless Dir.exist?(directory)
          raise "proj is not in a directory"
        end
        @plists = Find.find(directory).select { |p| /^.*Info\.plist$/ =~ p }
      end

      def find_bundle_version(lists)
        find_bundle_and_build_version(lists)[0]
      end

      def find_build_version(lists)
        find_bundle_and_build_version(lists)[1]
      end

      def find_bundle_and_build_version(lists)
        versions = []
        for list in lists do
          list_hash = Xcodeproj::PlistHelper.read list
          versions[0] ||= list_hash["CFBundleShortVersionString"]
          versions[1] ||= list_hash["CFBundleVersion"]
        end
      end

    end
  end
end<commit_msg>rearranging finding code and making a function private<commit_after>require 'xcodeproj'
require 'semantic'
require 'find'

module Timewizard
  module Versioner
    class Apple
      attr_accessor :dir
      attr_reader :proj
      attr_reader :plists
      attr_reader :old_bundle_version
      attr_reader :old_build_number
      attr_accessor :new_bundle_version
      attr_accessor :new_build_number

      #
      # Public functions
      #

      public

      def initialize(dir)
        @dir = dir
        @proj = nil
        @plists = []
      end

      def find_xcode_project()
        if @dir.nil?
          raise "directory cannot be nil"
        end
        if @dir.end_with? ".xcodeproj"
          @proj = File.absolute_path(@dir)
        else
          Find.find(@dir) do |path|
            unless path.to_s.end_with? ".xcodeproj"
              next
            end
            @proj = path
          end
        end
        @proj
      end

      def find_plists()
        if @proj.nil?
          raise "there is no .xcodeproj"
        end
        directory = File.dirname(@proj.to_s)
        unless Dir.exist?(directory)
          raise "proj is not in a directory"
        end
        @plists = []
        Find.find(directory) do |p|
          if /^.*Info\.plist$/ =~ p
            @plists << p
          end
        end
        @plists
      end

      def find_bundle_version(lists)
        find_bundle_and_build_version(lists)[0]
      end

      def find_build_version(lists)
        find_bundle_and_build_version(lists)[1]
      end

      #
      # Private functions
      #

      private

      def find_bundle_and_build_version(lists)
        versions = []
        for list in lists do
          list_hash = Xcodeproj::PlistHelper.read list
          versions[0] ||= list_hash["CFBundleShortVersionString"]
          versions[1] ||= list_hash["CFBundleVersion"]
        end
        versions
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.07867344468651659, 'fraction_numerical': 0.0019365770999757927, 'mean_word_length': 1.745514950166113, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4648576', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1227, 'n_words': 307}