Sha256: 8885260618e04d7b51a90cd4751aa3067c9412460afa477e578de06785408fbf

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 KB

Contents

require 'xcodeproject/node'
require 'pathname'

module XcodeProject
	class FileNode < Node
		attr_reader :name
		attr_reader :path
		attr_reader :source_tree

		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

		def source_tree
			SourceTreeMap[@source_tree]
		end

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

		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

		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

	private

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

	end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
xcodeproject-0.3.10 lib/xcodeproject/file_node.rb
xcodeproject-0.3.9 lib/xcodeproject/file_node.rb
xcodeproject-0.3.8 lib/xcodeproject/file_node.rb
xcodeproject-0.3.6 lib/xcodeproject/file_node.rb
xcodeproject-0.3.5 lib/xcodeproject/file_node.rb
xcodeproject-0.3.1 lib/xcodeproject/file_node.rb
xcodeproject-0.3.0 lib/xcodeproject/file_node.rb
xcodeproject-0.2.4 lib/xcodeproject/file_node.rb
xcodeproject-0.2.3 lib/xcodeproject/file_node.rb