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.



46
47
48
49
50
51
# File 'lib/watobo/core/intercept_filter.rb', line 46

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.



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

def flags
  @flags
end

#match_typeObject (readonly)

Returns the value of attribute match_type.



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

def match_type
  @match_type
end

#patternObject (readonly)

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

Instance Method Details

#match?(item, flags) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/watobo/core/intercept_filter.rb', line 40

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

#nameObject



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

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

#negate=(state) ⇒ Object



36
37
38
# File 'lib/watobo/core/intercept_filter.rb', line 36

def negate=(state)
  @negate = state
end

#negated?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/watobo/core/intercept_filter.rb', line 32

def negated?
  @negate
end