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.



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

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

Instance Attribute Details

#filtersObject

Available filter



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

def filters
  @filters
end

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

Class Method Details

.call(data, filters) ⇒ Object



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

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

Instance Method Details

#call!Object



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

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