class Eco::API::UseCases::GraphQL::Helpers::Location::TagsRemap::TagsMap

def <=>(other) # rubocop:disable Metrics/AbcSize

Other tags:
    Note: - to create a stable sort we assume `self` is a sorted element
def <=>(other) # rubocop:disable Metrics/AbcSize

  return -1 if maps?   && !other.maps?
  return  1 if !maps?  && other.maps?
  return -1 if rename? && other.move?
  return  1 if move?   && other.rename?
  return -1 if rename? && other.rename?
  # both are being moved (specific/long mappings first)

  return  1 if from.subset_of?(other.from)
  return -1 if from.superset_of?(other.from)
  return -1 if (from & other.from).empty?
  return -1 if from.length >= other.from.length
  return  1 if from.length <  other.from.length
  -1
end

def any?(&block)

def any?(&block)
  [from, to].any?(&block)
end

def both?(&block)

def both?(&block)
  [from, to].all?(&block)
end

def goes_after?(other)

Other tags:
    Note: - to create a stable sort we assume `self` is a sorted element
def goes_after?(other)
  (self <=> other) == 1
end

def goes_before?(other)

Other tags:
    Note: - to create a stable sort we assume `self` is a sorted element
def goes_before?(other)
  (self <=> other) == -1
end

def initialize(from, to)

def initialize(from, to)
  @from = TagsSet.new(from)
  @to   = TagsSet.new(to)
end

def maps?

def maps?
  return false if any?(&:empty?)
  return false if from == to
  true
end

def move?

def move?
  return false unless maps?
  !rename?
end

def rename?

def rename?
  return false unless maps?
  both? {|set| set.length == 1}
end

def to_csv_row

def to_csv_row
  [from.to_s, to.to_s]
end