Class: ServerPath
- Inherits:
-
Struct
- Object
- Struct
- ServerPath
- Includes:
- Comparable
- Defined in:
- lib/common.rb,
lib/apiobjects.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
Returns the value of attribute parts.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Variables are after fixed strings.
-
#compare(p, range = nil) ⇒ Object
Not fit for sorting.
-
#initialize(parts) ⇒ ServerPath
constructor
A new instance of ServerPath.
Constructor Details
#initialize(parts) ⇒ ServerPath
Returns a new instance of ServerPath.
120 121 122 |
# File 'lib/apiobjects.rb', line 120 def initialize(parts) @parts = parts end |
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts
75 76 77 |
# File 'lib/common.rb', line 75 def parts @parts end |
Instance Method Details
#<=>(other) ⇒ Object
Variables are after fixed strings.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/common.rb', line 77 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.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/common.rb', line 96 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 |