Class: Yast::Ops::ListComparator Deprecated

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
src/ruby/yast/ops.rb

Overview

Deprecated.

array usually don't need comparing

Implements ycp compatible comparison of lists. Difference is only that it use GenericComparator for each of its element.

Instance Method Summary collapse

Constructor Details

#initialize(value, localized = false) ⇒ ListComparator

Returns a new instance of ListComparator



432
433
434
435
# File 'src/ruby/yast/ops.rb', line 432

def initialize(value, localized = false)
  @value = value
  @localized = localized
end

Instance Method Details

#<=>(other) ⇒ Object



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'src/ruby/yast/ops.rb', line 437

def <=>(other)
  min_size = [@value.size, other.size].min
  0.upto(min_size - 1) do |i|
    # stupid nil handling
    fval = @value[i]
    sval = other[i]

    return 1 if sval.nil? && !fval.nil?

    # we need to use out builtin, but also we need to
    res = Ops.comparable_object(fval, @localized) <=> sval
    return res if res != 0
  end
  # no decision yet
  @value.size <=> other.size
end