Class: GrubY::Filters::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/gruubY/filters.rb

Direct Known Subclasses

EntityFilter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "Filter", &block) ⇒ Filter

Returns a new instance of Filter.



8
9
10
11
# File 'lib/gruubY/filters.rb', line 8

def initialize(name = "Filter", &block)
  @name = name
  @block = block || proc { true }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/gruubY/filters.rb', line 6

def name
  @name
end

Instance Method Details

#&(other) ⇒ Object



17
18
19
# File 'lib/gruubY/filters.rb', line 17

def &(other)
  Filter.new("(#{name}&#{other.name})") { |*args| call(*args) && other.call(*args) }
end

#call(*args) ⇒ Object



13
14
15
# File 'lib/gruubY/filters.rb', line 13

def call(*args)
  @block.call(*args)
end

#|(other) ⇒ Object



21
22
23
# File 'lib/gruubY/filters.rb', line 21

def |(other)
  Filter.new("(#{name}|#{other.name})") { |*args| call(*args) || other.call(*args) }
end

#~@Object



25
26
27
# File 'lib/gruubY/filters.rb', line 25

def ~@
  Filter.new("~#{name}") { |*args| !call(*args) }
end