Class: Xcode::PBXGroup

Inherits:
Object
  • Object
show all
Includes:
PBXFormatter
Defined in:
lib/xcode/pbx_group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PBXFormatter

#to_pbx

Constructor Details

#initialize(attributes) ⇒ PBXGroup

Returns a new instance of PBXGroup.



35
36
37
38
# File 'lib/xcode/pbx_group.rb', line 35

def initialize(attributes)
  @id = Xcode.register(self)
  @attributes = attributes
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



5
6
7
# File 'lib/xcode/pbx_group.rb', line 5

def groups
  @groups
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/xcode/pbx_group.rb', line 5

def id
  @id
end

Class Method Details

.new_from_directory(directory, file_type) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/xcode/pbx_group.rb', line 7

def self.new_from_directory(directory, file_type)
  children = []
  Dir.entries(directory).each do |entry|
    next if entry =~ /^\./
    filetype = File.ftype(directory + "/" + entry)
    filetype = "file" if File.extname(entry) == ".framework"
    case filetype
    when "directory"
      group = PBXGroup.new_from_directory(directory + "/" + entry, file_type)
      children << group
    when "file"
      file_ref = Xcode::PBXFileReference.new_from_file(directory + "/" + entry, file_type)
      children << file_ref
    else
      raise "wtf? #{directory} #{entry} #{File.ftype(directory + "/" + entry)}"
    end
  end
  new "children" => children.map(&:id), "path" => File.basename(directory)
end

.new_from_subdirectory(directory, file_type) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/xcode/pbx_group.rb', line 27

def self.new_from_subdirectory(directory, file_type)
  paths = directory.split("/")
  bottom = new_from_directory(directory, file_type)
  paths[0..-2].reverse.inject(bottom) do |child, path|
    new "path" => path, "children" => [child.id]
  end
end

Instance Method Details

#attributesObject



40
41
42
43
44
45
# File 'lib/xcode/pbx_group.rb', line 40

def attributes
  {
    "isa" => "PBXGroup",
    "sourceTree" => "<group>"
  }.merge @attributes
end