Class: Xcodeproj::Workspace::FileReference
- Inherits:
-
Object
- Object
- 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.
-
#type ⇒ String
readonly
This can be of the following values: - absolute - group - container - developer (unsupported).
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.
Constructor Details
#initialize(path, type = 'group') ⇒ FileReference
Returns a new instance of FileReference.
23 24 25 26 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 23 def initialize(path, type = 'group') @path = path.to_s @type = type.to_s end |
Instance Attribute Details
#path ⇒ String (readonly)
Returns the path to the project.
8 9 10 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 8 def path @path end |
#type ⇒ String (readonly)
This can be of the following values:
-
absolute
-
group
-
container
-
developer (unsupported)
18 19 20 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 18 def type @type end |
Class Method Details
.from_node(xml_node) ⇒ FileReference
Returns a file reference given XML representation.
48 49 50 51 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 48 def self.from_node(xml_node) type, path = xml_node.attribute('location').value.split(':', 2) new(path, type) end |
Instance Method Details
#==(other) ⇒ Bool Also known as: eql?
Returns Wether a file reference is equal to another.
30 31 32 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 30 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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 69 def absolute_path(workspace_dir_path) workspace_dir_path = workspace_dir_path.to_s case type when 'group' File.(File.join(workspace_dir_path, path)) when 'container' File.(File.join(workspace_dir_path, path)) when 'absolute' File.(path) when 'developer' raise 'Developer workspace file reference type is not yet ' \ "#{self}" else raise "Unsupported workspace file reference type #{type}" end end |
#hash ⇒ Fixnum
Returns A hash identical for equals objects.
37 38 39 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 37 def hash [path, type].hash end |
#to_node ⇒ REXML::Element
Returns the XML representation of the file reference.
55 56 57 58 59 |
# File 'lib/xcodeproj/workspace/file_reference.rb', line 55 def to_node REXML::Element.new('FileRef').tap do |element| element.add_attribute('location', "#{type}:#{path}") end end |