Class: Xcodeproj::Workspace::FileReference
- Defined in:
- lib/xcodeproj/workspace/file_reference.rb
Overview
Describes a file reference of a Workspace.
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
The path to the project.
Attributes inherited from Reference
Class Method Summary collapse
-
.from_node(xml_node) ⇒ FileReference
Returns a file reference given XML representation.
Instance Method Summary collapse
-
#==(other) ⇒ Bool
(also: #eql?)
Wether a file reference is equal to another.
-
#absolute_path(workspace_dir_path) ⇒ String
Returns the absolute path of a file reference given the path of the directory containing workspace.
-
#hash ⇒ Fixnum
A hash identical for equals objects.
-
#initialize(path, type = 'group') ⇒ FileReference
constructor
A new instance of FileReference.
-
#to_node ⇒ REXML::Element
The XML representation of the file reference.
Methods inherited from Reference
Constructor Details
#initialize(path, type = 'group') ⇒ FileReference
Returns a new instance of FileReference.
15 16 17 18 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 15 def initialize(path, type = 'group') @path = Pathname.new(path.to_s).cleanpath.to_s @type = type.to_s end |
Instance Attribute Details
#path ⇒ String (readonly)
Returns the path to the project.
10 11 12 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 10 def path @path end |
Class Method Details
.from_node(xml_node) ⇒ FileReference
Returns a file reference given XML representation.
40 41 42 43 44 45 46 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 40 def self.from_node(xml_node) type, path = xml_node.attribute('location').value.split(':', 2) if type == 'group' path = prepend_parent_path(xml_node, path) end new(path, type) end |
Instance Method Details
#==(other) ⇒ Bool Also known as: eql?
Returns Wether a file reference is equal to another.
22 23 24 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 22 def ==(other) path == other.path && type == other.type end |
#absolute_path(workspace_dir_path) ⇒ String
Returns the absolute path of a file reference given the path of the directory containing workspace.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 64 def absolute_path(workspace_dir_path) workspace_dir_path = workspace_dir_path.to_s case type when 'group', 'container', 'self' File.(File.join(workspace_dir_path, path)) when 'absolute' File.(path) when 'developer' raise "Developer workspace file reference type is not yet supported (#{path})" else raise "Unsupported workspace file reference type `#{type}`" end end |
#hash ⇒ Fixnum
Returns A hash identical for equals objects.
29 30 31 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 29 def hash [path, type].hash end |
#to_node ⇒ REXML::Element
Returns the XML representation of the file reference.
50 51 52 53 54 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 50 def to_node REXML::Element.new('FileRef').tap do |element| element.add_attribute('location', "#{type}:#{path}") end end |