Class: Watobo::Interceptor::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/watobo/core/intercept_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, prefs = {}) ⇒ Filter

Returns a new instance of Filter.



25
26
27
28
29
30
# File 'lib/watobo/core/intercept_filter.rb', line 25

def initialize(pattern, prefs={})
  @flags = prefs.has_key?(:flags) ? prefs[:flags] : []
  @match_type = prefs.has_key?(:match_type) ? prefs[:match_type] : :match
  @negate = ( @match_type.to_s =~ /^not/ )
  @pattern = pattern
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



6
7
8
# File 'lib/watobo/core/intercept_filter.rb', line 6

def flags
  @flags
end

#match_typeObject (readonly)

Returns the value of attribute match_type.



6
7
8
# File 'lib/watobo/core/intercept_filter.rb', line 6

def match_type
  @match_type
end

#patternObject (readonly)

Returns the value of attribute pattern.



6
7
8
# File 'lib/watobo/core/intercept_filter.rb', line 6

def pattern
  @pattern
end

Instance Method Details

#match?(item, flags) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/watobo/core/intercept_filter.rb', line 19

def match?(item, flags)
 
  return !check?(item, flags) if @negate == true
  return check?(item, flags)
end

#nameObject



7
8
9
# File 'lib/watobo/core/intercept_filter.rb', line 7

def name
  self.class.to_s.gsub(/.*::/,'')
end

#negate=(state) ⇒ Object



15
16
17
# File 'lib/watobo/core/intercept_filter.rb', line 15

def negate=(state)
  @negate = state
end

#negated?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/watobo/core/intercept_filter.rb', line 11

def negated?
  @negate
end