Class: XCodeProject::FileNode

Inherits:
Node
  • Object
show all
Defined in:
lib/xcodeproject/file_node.rb

Direct Known Subclasses

PBXFileReference, PBXGroup

Instance Attribute Summary collapse

Attributes inherited from Node

#isa, #uuid

Instance Method Summary collapse

Constructor Details

#initialize(root, uuid, data) ⇒ FileNode

Returns a new instance of FileNode.



10
11
12
13
14
15
16
17
18
# File 'lib/xcodeproject/file_node.rb', line 10

def initialize (root, uuid, data)
	super(root, uuid, data)

	@source_tree = data['sourceTree']
	@name ||= data['name']
	@path ||= data['path']

	@name ||= File.basename(@path) unless @path.nil?
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/xcodeproject/file_node.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/xcodeproject/file_node.rb', line 7

def path
  @path
end

#source_treeObject (readonly)

Returns the value of attribute source_tree.



8
9
10
# File 'lib/xcodeproject/file_node.rb', line 8

def source_tree
  @source_tree
end

Instance Method Details

#group_pathObject



30
31
32
33
34
35
36
37
38
# File 'lib/xcodeproject/file_node.rb', line 30

def group_path
	obj = self
	res = ''
	begin
		pn = obj.name ? obj.name : ''
		res = Pathname.new(pn).join(res)
	end while obj = obj.parent;
	res.cleanpath
end

#parentObject



24
25
26
27
28
# File 'lib/xcodeproject/file_node.rb', line 24

def parent
	root.select_objects do |uuid, data|
		(data['children'].include?(self.uuid) if data['isa'] == 'PBXGroup') ? true : false
	end.first
end

#total_pathObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/xcodeproject/file_node.rb', line 40

def total_path
	res = ''
	case source_tree
		when :source_root
			res = path
		when :group
			pn = path.nil? ? '' : path
			res = parent.total_path.join(pn) unless parent.nil?
		else
			raise ParseError.new("No such '#{source_tree}' source tree type.")
	end
	root.absolute_path(res)
end