Class: Yast::Path
- Inherits:
-
Object
- Object
- Yast::Path
- Includes:
- Comparable
- Defined in:
- src/ruby/yast/path.rb,
src/ruby/yast/yast.rb
Overview
Represents paths like it is in ycp. It is path elements separated by dot.
Elements can be simple or complex. Simple can contain only ascii characters [a-zA-Z0-9].
Complex elements are enclosed by "
and can contain all characters.
Immutable class
Class Method Summary collapse
-
.from_string(string) ⇒ Object
Creates path from generic string.
Instance Method Summary collapse
-
#+(other) ⇒ Object
concats path.
- #<=>(other) ⇒ Object
- #clone ⇒ Object
-
#empty? ⇒ Boolean
Detect if there is no elements.
-
#initialize(value) ⇒ Path
constructor
any element starts or ends with dash like ".-etc", ".etc-" or ".e.t-.c".
-
#size ⇒ Object
gets number of elements.
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ Path
any element starts or ends with dash like ".-etc", ".etc-" or ".e.t-.c"
13 14 15 16 17 18 19 20 |
# File 'src/ruby/yast/path.rb', line 13 def initialize(value) if !value.is_a?(::String) raise ArgumentError, "Yast::Path constructor has to get ::String as " \ "argument instead of '#{value.inspect}'" end @components = [] load_components value end |
Class Method Details
.from_string(string) ⇒ Object
Creates path from generic string
23 24 25 |
# File 'src/ruby/yast/path.rb', line 23 def self.from_string(string) new ".\"#{string}\"" end |
Instance Method Details
#+(other) ⇒ Object
concats path
32 33 34 35 36 37 |
# File 'src/ruby/yast/path.rb', line 32 def +(other) other = self.class.from_string(other) unless other.is_a? Yast::Path return other.clone if components.empty? return clone if other.empty? Path.new(to_s + other.to_s) end |
#<=>(other) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'src/ruby/yast/path.rb', line 53 def <=>(other) return nil unless other.is_a? self.class 0.upto(size - 1) do |i| return 1 unless other.send(:components)[i] # we strip enclosing quotes for complex expression our_component = components[i].sub(/\A"(.*)"\Z/, "\\1") other_component = other.send(:components)[i].sub(/\A"(.*)"\Z/, "\\1") res = our_component <=> other_component return res if res != 0 end size <=> other.size end |
#clone ⇒ Object
27 28 29 |
# File 'src/ruby/yast/path.rb', line 27 def clone self end |
#empty? ⇒ Boolean
Detect if there is no elements
49 50 51 |
# File 'src/ruby/yast/path.rb', line 49 def empty? components.empty? end |
#size ⇒ Object
gets number of elements
44 45 46 |
# File 'src/ruby/yast/path.rb', line 44 def size components.size end |
#to_s ⇒ Object
39 40 41 |
# File 'src/ruby/yast/path.rb', line 39 def to_s "." + components.join(".") end |