Class: Xcodeproj::Workspace::GroupReference

Inherits:
Reference
  • Object
show all
Defined in:
lib/xcodeproj/workspace/group_reference.rb

Overview

Describes a group reference of a Workspace.

Instance Attribute Summary collapse

Attributes inherited from Reference

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Reference

prepend_parent_path

Constructor Details

#initialize(name, type = 'container', location = '') ⇒ GroupReference

Returns a new instance of GroupReference.

Parameters:

  • name (#to_s)

    @see name

  • type (#to_s) (defaults to: 'container')

    @see type

  • location (#to_s) (defaults to: '')

    @see location



20
21
22
23
24
# File 'lib/xcodeproj/workspace/group_reference.rb', line 20

def initialize(name, type = 'container', location = '')
  @name = name.to_s
  @type = type.to_s
  @location = location.to_s
end

Instance Attribute Details

#locationString (readonly)

Returns the location of the group on disk.

Returns:

  • (String)

    the location of the group on disk



14
15
16
# File 'lib/xcodeproj/workspace/group_reference.rb', line 14

def location
  @location
end

#nameString (readonly)

Returns the name of the group.

Returns:

  • (String)

    the name of the group



10
11
12
# File 'lib/xcodeproj/workspace/group_reference.rb', line 10

def name
  @name
end

Class Method Details

.from_node(xml_node) ⇒ GroupReference

Returns a group reference given XML representation.

Parameters:

  • xml_node (REXML::Element)

    the XML representation.

Returns:



46
47
48
49
50
51
52
53
54
55
# File 'lib/xcodeproj/workspace/group_reference.rb', line 46

def self.from_node(xml_node)
  location_array = xml_node.attribute('location').value.split(':', 2)
  type = location_array.first
  location = location_array[1] || ''
  if type == 'group'
    location = prepend_parent_path(xml_node, location)
  end
  name = xml_node.attribute('name').value
  new(name, type, location)
end

Instance Method Details

#==(other) ⇒ Bool Also known as: eql?

Returns Whether a group reference is equal to another.

Returns:

  • (Bool)

    Whether a group reference is equal to another.



28
29
30
# File 'lib/xcodeproj/workspace/group_reference.rb', line 28

def ==(other)
  name == other.name && type == other.type && location == other.location
end

#hashFixnum

Returns A hash identical for equals objects.

Returns:

  • (Fixnum)

    A hash identical for equals objects.



35
36
37
# File 'lib/xcodeproj/workspace/group_reference.rb', line 35

def hash
  [name, type, location].hash
end

#to_nodeREXML::Element

Returns the XML representation of the group reference.

Returns:

  • (REXML::Element)

    the XML representation of the group reference.



59
60
61
62
63
64
# File 'lib/xcodeproj/workspace/group_reference.rb', line 59

def to_node
  REXML::Element.new('Group').tap do |element|
    element.add_attribute('location', "#{type}:#{location}")
    element.add_attribute('name', "#{name}")
  end
end