Class: Selector::Collection

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

Overview

The condition checks if a value is included to the collection

Examples:

condition = Set.new [:foo, :bar]
condition[:foo] # => true
condition[:baz] # => false

Direct Known Subclasses

Array

Instance Attribute Summary

Attributes inherited from Condition

#attributes

Instance Method Summary collapse

Methods inherited from Condition

#!, #&, #-, #==, #attribute, #|

Constructor Details

#initialize(collection) ⇒ Collection

Initializes the condition with a collection of allowed values

Parameters:

  • collection (Enumerable)


16
17
18
# File 'lib/selector/collection.rb', line 16

def initialize(_)
  super
end

Instance Method Details

#[](value) ⇒ Boolean

Checks if the array includes the value

Examples:

condition = Set.new [:foo, :bar]
condition[:foo] # => true
condition[:baz] # => false

Parameters:

  • value (Object)

Returns:

  • (Boolean)


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

def [](value)
  attribute.include? value
end