Class: NoyesFilterDSL::ParallelFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/common/parallel_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filters = []) ⇒ ParallelFilter



4
5
6
# File 'lib/common/parallel_filter.rb', line 4

def initialize filters=[]
  @filters = filters.kind_of?(Array) ? filters : [filters]
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters



3
4
5
# File 'lib/common/parallel_filter.rb', line 3

def filters
  @filters
end

Instance Method Details

#&(other) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/common/parallel_filter.rb', line 15

def & other
  raise "Parameter does not respond to <<." unless other.respond_to? :<<
  if other.kind_of?(ParallelFilter) && filters.size != other.filters.size
    raise "Parallel filters must have equal dimensions %d vs %d " %
      [filters.size, other.filters.size]
  end
  other_filters = if other.kind_of? SerialFilter
    other.filters.clone
  else
    other
  end
  SerialFilter.new([ParallelFilter.new(filters.clone),  other_filters].flatten)
end

#<<(data) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/common/parallel_filter.rb', line 7

def << data
  if data.size != @filters.size
    raise "data (%d) and filters (%d) must have same dimensions." %
      [data.size, @filters.size]
  end
  offset = -1
  @filters.map {|f| f << data[offset+=1]}
end

#|(other) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/common/parallel_filter.rb', line 28

def | other
  raise "Parameter does not respond to <<." unless other.respond_to? :<<
  if other.kind_of? ParallelFilter
    return ParallelFilter.new(@filters + other.filters)
  end
  ParallelFilter.new((@filters + other).flatten)
end