Class: ReeDto::CollectionFilter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, Ree::Contracts::ArgContracts, Ree::Contracts::Core
Defined in:
lib/ree_lib/packages/ree_dto/package/ree_dto/dto/collection_filter.rb

Constant Summary collapse

InvalidFilterItemErr =
Class.new(ArgumentError)

Instance Method Summary collapse

Constructor Details

#initialize(collection, name, filter_proc) ⇒ CollectionFilter

Returns a new instance of CollectionFilter.



12
13
14
15
16
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/collection_filter.rb', line 12

def initialize(collection, name, filter_proc)
  @collection = collection
  @name = name
  @filter_proc = filter_proc
end

Instance Method Details

#add(item) ⇒ Object Also known as: <<, push



28
29
30
31
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/collection_filter.rb', line 28

def add(item)
  check_item(item)
  @collection.add(item)
end

#allObject



23
24
25
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/collection_filter.rb', line 23

def all
  @collection.select(&@filter_proc)
end

#each(&block) ⇒ Object



19
20
21
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/collection_filter.rb', line 19

def each(&block)
  @collection.select(&@filter_proc).each(&block)
end

#inspectObject



33
34
35
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/collection_filter.rb', line 33

def inspect
  to_a.inspect
end

#remove(item) ⇒ Object



38
39
40
41
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/collection_filter.rb', line 38

def remove(item)
  check_item(item)
  @collection.remove(item)
end