Class: ServerPath

Inherits:
Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/common.rb,
lib/apiobjects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parts) ⇒ ServerPath

Returns a new instance of ServerPath.



116
117
118
# File 'lib/apiobjects.rb', line 116

def initialize(parts)
  @parts = parts
end

Instance Attribute Details

#partsObject

Returns the value of attribute parts

Returns:

  • (Object)

    the current value of parts



71
72
73
# File 'lib/common.rb', line 71

def parts
  @parts
end

Instance Method Details

#<=>(other) ⇒ Object

Variables are after fixed strings.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/common.rb', line 73

def <=>(other)
  pp = other.is_a?(Array) ? other : other.parts
  parts.each_index do |k|
    return 1 if pp.size <= k # Longer comes after shorter.
    pk = parts[k]
    ppk = pp[k]
    if pk.is_a? String
      return -1 unless ppk.is_a? String
      c = pk <=> ppk
    else
      return 1 if ppk.is_a? String
      c = pk.fetch('var', '') <=> ppk.fetch('var', '')
    end
    return c unless c.zero?
  end
  (parts.size < pp.size) ? -1 : 0
end

#compare(p, range = nil) ⇒ Object

Not fit for sorting. Variable equals anything.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/common.rb', line 92

def compare(p, range = nil)
  pp = p.is_a?(Array) ? p : p.parts
  if range.nil?
    range = 0...parts.size
  elsif range.is_a? Number
    range = range...(range + 1)
  end
  range.each do |k|
    return 1 if pp.size <= k # Longer comes after shorter.
    ppk = pp[k]
    next unless ppk.is_a? String
    pk = parts[k]
    next unless pk.is_a? String
    c = pk <=> ppk
    return c unless c.zero?
  end
  (parts.size < pp.size) ? -1 : 0
end