Class: Selector::Not

Inherits:
Condition show all
Defined in:
lib/selector/not.rb

Overview

The inversion of another condition

Instance Attribute Summary

Attributes inherited from Condition

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Condition

#&, #-, #==, #attribute, #initialize, #|

Constructor Details

This class inherits a constructor from Selector::Condition

Class Method Details

.new(source) ⇒ Object



10
11
12
13
14
# File 'lib/selector/not.rb', line 10

def self.new(source)
  return NOTHING  if source.equal? ANYTHING
  return ANYTHING if source.equal? NOTHING
  super
end

Instance Method Details

#!Selector::Condition

Returns the inverted condition (avoids double negation)

Examples:

condition = Selector.new(only: [:foo])
inversion = Not.new(condition)
!inversion == condition # => true

Returns:



44
45
46
# File 'lib/selector/not.rb', line 44

def !
  attribute
end

#[](value) ⇒ Boolean

Checks if the value doesn’t satisfy inverted condition

Examples:

condition = Selector.new(only: [:foo])
inversion[:foo] # => true
inversion[:bar] # => false

inversion = Not.new(condition)
inversion[:foo] # => false
inversion[:bar] # => true

Parameters:

  • value (Object)

Returns:

  • (Boolean)


31
32
33
# File 'lib/selector/not.rb', line 31

def [](value)
  !attribute[value]
end