Class: XcodeProject::FileNode

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

Direct Known Subclasses

PBXFileReference, PBXGroup

Constant Summary collapse

SourceTreeMap =
{
  'SOURCE_ROOT' => :source_root,
  '<group>' => :group
}.freeze

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.



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

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.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#source_treeObject (readonly)

Returns the value of attribute source_tree.



32
33
34
# File 'lib/xcodeproject/file_node.rb', line 32

def source_tree
  @source_tree
end

Instance Method Details

#group_pathObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/xcodeproject/file_node.rb', line 54

def group_path
  obj = self
  res = ''
  loop do
    pn = obj.name ? obj.name : ''
    res = Pathname.new(pn).join(res)
    break unless (obj = obj.parent)
  end
  res.cleanpath
end

#parentObject



48
49
50
51
52
# File 'lib/xcodeproject/file_node.rb', line 48

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

#total_pathObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/xcodeproject/file_node.rb', line 65

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, "No such '#{source_tree}' source tree type."
  end
  root.absolute_path(res)
end