Class: OpenAPISourceTools::ApiObjects::ServerPath
- Inherits:
-
Object
- Object
- OpenAPISourceTools::ApiObjects::ServerPath
- Includes:
- Comparable
- Defined in:
- lib/openapi/sourcetools/apiobjects.rb
Overview
Represents path with fixed parts and variables.
Instance Attribute Summary collapse
-
#parts ⇒ Object
Returns the value of attribute parts.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Parameters are after fixed strings.
-
#compare(other, 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.
231 232 233 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 231 def initialize(parts) @parts = parts end |
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts.
229 230 231 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 229 def parts @parts end |
Instance Method Details
#<=>(other) ⇒ Object
Parameters are after fixed strings.
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 236 def <=>(other) pp = other.is_a?(Array) ? other : other.parts @parts.size.times do |k| return 1 if pp.size <= k # Longer comes after shorter. pk = @parts[k] ppk = pp[k] if pk.key?('fixed') if ppk.key?('fixed') c = pk['fixed'] <=> ppk['fixed'] else return -1 end else if ppk.key?('fixed') return 1 else c = pk.fetch('parameter', '') <=> ppk.fetch('parameter', '') end end return c unless c.zero? end (@parts.size < pp.size) ? -1 : 0 end |
#compare(other, range = nil) ⇒ Object
Not fit for sorting. Variable equals anything.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 261 def compare(other, range = nil) pp = other.is_a?(Array) ? other : other.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.key?('fixed') pk = parts[k] next unless pk.key?('fixed') c = pk['fixed'] <=> ppk['fixed'] return c unless c.zero? end (@parts.size < pp.size) ? -1 : 0 end |