Class: GrubY::Filters::EntityFilter

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

Instance Attribute Summary collapse

Attributes inherited from Filter

#name

Instance Method Summary collapse

Methods inherited from Filter

#&, #call, #|, #~@

Constructor Details

#initialize(name, values = nil, &matcher) ⇒ EntityFilter

Returns a new instance of EntityFilter.



33
34
35
36
37
38
39
# File 'lib/gruubY/filters.rb', line 33

def initialize(name, values = nil, &matcher)
  @values = normalize(values)
  @matcher = matcher
  super(name) do |_filter, _client, update|
    @matcher.call(update, @values)
  end
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



31
32
33
# File 'lib/gruubY/filters.rb', line 31

def values
  @values
end

Instance Method Details

#add(value) ⇒ Object



41
42
43
44
# File 'lib/gruubY/filters.rb', line 41

def add(value)
  @values.merge(normalize(value))
  self
end

#clearObject



51
52
53
54
# File 'lib/gruubY/filters.rb', line 51

def clear
  @values.clear
  self
end

#delete(value) ⇒ Object



46
47
48
49
# File 'lib/gruubY/filters.rb', line 46

def delete(value)
  normalize(value).each { |v| @values.delete(v) }
  self
end