Class: KeySet::AllExceptSome

Inherits:
KeySet
  • Object
show all
Includes:
BasedOnKeys
Defined in:
lib/key_set/all_except_some.rb

Constant Summary

Constants inherited from KeySet

VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BasedOnKeys

#clone, #keys_array, #represents_all?, #represents_none?

Methods inherited from KeySet

#<=>, #==, #===, all, all_except_some, default_logger, #eql?, #hash, logger, none, #represents_all?, #represents_none?, some

Class Method Details

.class_sort_indexObject



7
8
9
# File 'lib/key_set/all_except_some.rb', line 7

def self.class_sort_index
  2
end

Instance Method Details

#intersect(other) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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

#invertObject



11
12
13
# File 'lib/key_set/all_except_some.rb', line 11

def invert
  KeySet.some(keys_array)
end

#remove(other) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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