Sha256: ccd18ffa37aed3f6bc885b14ae1fd708fccf7684bd07767fac319ba556dd380e
Contents?: true
Size: 1.74 KB
Versions: 40
Compression:
Stored size: 1.74 KB
Contents
module Eco::API::UseCases::GraphQL::Helpers::Location class TagsRemap class TagsMap attr_reader :from, :to def initialize(from, to) @from = TagsSet.new(from) @to = TagsSet.new(to) end def to_csv_row [from.to_s, to.to_s] end # @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 # @note to create a stable sort we assume `self` is a sorted element def goes_before?(other) (self <=> other) == -1 end # @note to create a stable sort we assume `self` is a sorted element def goes_after?(other) (self <=> other) == 1 end def both?(&block) [from, to].all?(&block) end def any?(&block) [from, to].any?(&block) end def maps? return false if any?(&:empty?) return false if from == to true end def rename? return false unless maps? both? {|set| set.length == 1} end def move? return false unless maps? !rename? end end end end
Version data entries
40 entries across 40 versions & 1 rubygems