Class: Recollect::Array::Filterable

Inherits:
Object
  • Object
show all
Defined in:
lib/recollect/array/filterable.rb

Constant Summary collapse

PREDICATES =
%w[
  eq
  noteq
  not_eq
  cont
  notcont
  not_cont
  lt
  lteq
  gt
  gteq
  start
  notstart
  not_start
  end
  notend
  not_end
  in
  notin
  not_in
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, filters) ⇒ Filterable

Returns a new instance of Filterable.



39
40
41
42
# File 'lib/recollect/array/filterable.rb', line 39

def initialize(data, filters)
  @result = Array(data)
  @filters = filters
end

Instance Attribute Details

#filtersObject

Available filter



35
36
37
# File 'lib/recollect/array/filterable.rb', line 35

def filters
  @filters
end

#resultObject (readonly)

Returns the value of attribute result.



37
38
39
# File 'lib/recollect/array/filterable.rb', line 37

def result
  @result
end

Class Method Details

.call(data, filters) ⇒ Object



6
7
8
9
10
# File 'lib/recollect/array/filterable.rb', line 6

def self.call(data, filters)
  instance = new(data, filters)
  instance.call!
  instance
end

Instance Method Details

#call!Object



45
46
47
# File 'lib/recollect/array/filterable.rb', line 45

def call!
  @filters.each(&__apply_filter_callback)
end