Class: Installation::AutoinstProfile::ElementPath

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
library/general/src/lib/installation/autoinst_profile/element_path.rb

Overview

This class represents an element path in a profile

Examples:

Create a path

ElementPath.new("groups", 0, "groupname")

Join a path and a string

first = ElementPath.new("users", 1)
first.join("username").to_s #=> "users,1,username"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*parts) ⇒ ElementPath

Constructor

Parameters:

  • parts (Array<Integer,String>)

    Profile path parts



55
56
57
# File 'library/general/src/lib/installation/autoinst_profile/element_path.rb', line 55

def initialize(*parts)
  @parts = parts
end

Class Method Details

.from_string(str) ⇒ ElementPath

Returns an ElementPath object from a string

Examples:

Path to the username of the first user

ElementPath.from_string("users,0,username")

Parameters:

  • str (String)

    String to parse

Returns:



43
44
45
46
47
48
49
# File 'library/general/src/lib/installation/autoinst_profile/element_path.rb', line 43

def from_string(str)
  parts = str.split(",").each_with_object([]) do |part, all|
    element = (part =~ /\A\d+\Z/) ? part.to_i : part
    all.push(element)
  end
  new(*parts)
end

Instance Method Details

#==(other) ⇒ Boolean

Compares two paths

Two paths are considered to be equivalent if they have the same parts.

Parameters:

Returns:

  • (Boolean)

    true if they are equal; false otherwise



94
95
96
# File 'library/general/src/lib/installation/autoinst_profile/element_path.rb', line 94

def ==(other)
  @parts == other.to_a
end

#join(*parts_or_path) ⇒ ElementPath

Returns a new path composed by the given parts

Examples:

Extend a path with an string

path = ProfilePath.new("general")
path.join("mode") #=> ProfilePath.new("general", "mode")

Combine ProfilePath and strings

path = ProfilePath.new("general")
suffix = ProfilePath.new("mode")
path.join(suffix, "confirm") #=> ProfilePath.new("general", "mode", "confirm")

Parameters:

  • parts_or_path (Array<String,ProfilePath>)

    Parts or paths to join

Returns:



79
80
81
82
83
84
85
86
# File 'library/general/src/lib/installation/autoinst_profile/element_path.rb', line 79

def join(*parts_or_path)
  new_parts = parts_or_path.reduce([]) do |all, element|
    new_elements = element.respond_to?(:to_a) ? element.to_a : [element]
    all + new_elements
  end

  self.class.new(*(@parts + new_parts))
end

#to_aArray<Integer,String>

Returns the path parts

Returns:

  • (Array<Integer,String>)

    An array containing the path parts



62
63
64
# File 'library/general/src/lib/installation/autoinst_profile/element_path.rb', line 62

def to_a
  @parts
end

#to_sString

Returns a generic path (old AutoYaST path used in ask-lists)

Examples:

Path to the first user in the list

path = ElementPath.new("users", 1, "username")
path.to_s #=> "users,1,username"

Returns:

  • (String)


105
106
107
# File 'library/general/src/lib/installation/autoinst_profile/element_path.rb', line 105

def to_s
  @parts.join(",")
end