class KeySet::AllExceptSome

Public Class Methods

class_sort_index() click to toggle source
# File lib/key_set/all_except_some.rb, line 7
def self.class_sort_index
  2
end

Public Instance Methods

intersect(other) click to toggle source
# File lib/key_set/all_except_some.rb, line 35
def intersect(other)
  case other
  when All
    KeySet.all_except_some keys.deep_dup
  when None
    KeySet.none
  when Some
    # we have all except some, we remove some others => we have all except the ones that we didn't have before and the ones that we don't have now
    intersect_some(other)
  when AllExceptSome
    intersect_all_except_some(other)
  else
    raise ArgumentError, 'it needs a valid KeySet'
  end
end
invert() click to toggle source
# File lib/key_set/all_except_some.rb, line 11
def invert
  KeySet.some(keys_array)
end
remove(other) click to toggle source
# File lib/key_set/all_except_some.rb, line 15
def remove(other)
  case other
  when All
    # we have all except some, we remove everything => we have nothing
    KeySet.none
  when None
    # we have all except some, we remove nothing => we have the same (all but these keys)
    KeySet.all_except_some keys.deep_dup
  when Some
    # we have all except some, we remove some others => we have all except the ones that we didn't have before and the ones that we don't have now
    remove_some(other)
  when AllExceptSome
    # we have all except some, we remove all except others => we have only the ones that OTHER did not remove, except the ones that THIS was removing
    KeySet.logger.warn "KeySet removing AllButSome, probably a mistake. this: ALL_BUT_SOME, removing keys: #{other.keys.inspect}"
    remove_all_except_some(other)
  else
    raise ArgumentError, 'it needs a valid KeySet'
  end
end

Private Instance Methods

intersect_all_except_some(other) click to toggle source
# File lib/key_set/all_except_some.rb, line 68
def intersect_all_except_some(other)
  k = other.keys.deep_dup + keys.deep_dup
  KeySet.all_except_some k
end
intersect_some(other) click to toggle source
# File lib/key_set/all_except_some.rb, line 63
def intersect_some(other)
  k = other.keys.deep_dup - keys.deep_dup
  KeySet.some k
end
remove_all_except_some(other) click to toggle source
# File lib/key_set/all_except_some.rb, line 58
def remove_all_except_some(other)
  k = other.keys.deep_dup - keys.deep_dup
  KeySet.some k
end
remove_some(other) click to toggle source
# File lib/key_set/all_except_some.rb, line 53
def remove_some(other)
  k = keys.deep_dup + other.keys.deep_dup
  KeySet.all_except_some k
end