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.



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

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.



28
29
30
# File 'lib/xcodeproject/file_node.rb', line 28

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



29
30
31
# File 'lib/xcodeproject/file_node.rb', line 29

def path
  @path
end

#source_treeObject (readonly)

Returns the value of attribute source_tree.



30
31
32
# File 'lib/xcodeproject/file_node.rb', line 30

def source_tree
  @source_tree
end

Instance Method Details

#group_pathObject



52
53
54
55
56
57
58
59
60
# File 'lib/xcodeproject/file_node.rb', line 52

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



46
47
48
49
50
# File 'lib/xcodeproject/file_node.rb', line 46

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

#total_pathObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/xcodeproject/file_node.rb', line 62

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