<commit_before>require 'fileutils'
require 'rexml/document'

module Xcodeproj

  # Provides support for generating, reading and serializing Xcode Workspace
  # documents.
  #
  class Workspace

    # @return [Array<String>] the paths of the projects contained in the
    #         workspace.
    #
    attr_reader :projpaths

    # @param  [String] projpaths @see projpaths
    #
    def initialize(*projpaths)
      @projpaths = projpaths
    end

    #-------------------------------------------------------------------------#

    # Returns a workspace generated by reading the contents of the given path.
    #
    # @param  [String] path
    #         the path of the `xcworkspace` file.
    #
    # @return [Workspace] the generated workspace.
    #
    def self.new_from_xcworkspace(path)
      begin
        from_s(File.read(File.join(path, 'contents.xcworkspacedata')))
      rescue Errno::ENOENT
        new
      end
    end

    # Returns a workspace generated by reading the contents of the given
    # XML representation.
    #
    # @param  [String] xml
    #         the XML representation of the workspace.
    #
    # @return [Workspace] the generated workspace.
    #
    def self.from_s(xml)
      document = REXML::Document.new(xml)
      projpaths = document.get_elements("/Workspace/FileRef").map do |node|
        node.attribute("location").to_s.sub(/^group:/, '')
      end
      new(*projpaths)
    end

    #-------------------------------------------------------------------------#

    # Adds a new path to the list of the of projects contained in the
    # workspace.
    #
    # @param  [String] projpath
    #         The path of the project to add.
    #
    # @return [void]
    #
    def <<(projpath)
      @projpaths << projpath
    end

    # Checks if the workspace contains the project with the given path.
    #
    # @param  [String] projpath
    #         The path of the project to add.
    #<commit_msg>[Workspace] Support initialization with an array<commit_after>require 'fileutils'
require 'rexml/document'

module Xcodeproj

  # Provides support for generating, reading and serializing Xcode Workspace
  # documents.
  #
  class Workspace

    # @return [Array<String>] the paths of the projects contained in the
    #         workspace.
    #
    attr_reader :projpaths

    # @param  [Array] projpaths @see projpaths
    #
    def initialize(*projpaths)
      @projpaths = projpaths.flatten
    end

    #-------------------------------------------------------------------------#

    # Returns a workspace generated by reading the contents of the given path.
    #
    # @param  [String] path
    #         the path of the `xcworkspace` file.
    #
    # @return [Workspace] the generated workspace.
    #
    def self.new_from_xcworkspace(path)
      begin
        from_s(File.read(File.join(path, 'contents.xcworkspacedata')))
      rescue Errno::ENOENT
        new
      end
    end

    # Returns a workspace generated by reading the contents of the given
    # XML representation.
    #
    # @param  [String] xml
    #         the XML representation of the workspace.
    #
    # @return [Workspace] the generated workspace.
    #
    def self.from_s(xml)
      document = REXML::Document.new(xml)
      projpaths = document.get_elements("/Workspace/FileRef").map do |node|
        node.attribute("location").to_s.sub(/^group:/, '')
      end
      new(projpaths)
    end

    #-------------------------------------------------------------------------#

    # Adds a new path to the list of the of projects contained in the
    # workspace.
    #
    # @param  [String] projpath
    #         The path of the project to add.
    #
    # @return [void]
    #
    def <<(projpath)
      @projpaths << projpath
    end

    # Checks if the workspace contains the project with the given path.
    #
    # @param  [String] projpath
    #         The path of the project to add.
    #
{'fraction_non_alphanumeric': 0.15705209656925032, 'fraction_numerical': 0.0, 'mean_word_length': 1.7895109851169384, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '7628770', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1092, 'n_words': 343}