Class: CQL::ContentMatchFilter

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

Overview

Not a part of the public API. Subject to change at any time.

Direct Known Subclasses

LineFilter, NameFilter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ ContentMatchFilter

Creates a new filter

Raises:

  • (ArgumentError)


39
40
41
42
43
# File 'lib/cql/filters.rb', line 39

def initialize(pattern)
  raise(ArgumentError, "Can only match a String or Regexp. Got #{pattern.class}.") unless pattern.is_a?(String) || pattern.is_a?(Regexp)

  @pattern = pattern
end

Instance Attribute Details

#patternObject (readonly)

Pattern to match



36
37
38
# File 'lib/cql/filters.rb', line 36

def pattern
  @pattern
end

Instance Method Details

#content_match?(content) ⇒ Boolean

Returns whether or not the content matches the pattern

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/cql/filters.rb', line 46

def content_match?(content)
  if pattern.is_a?(String)
    content.any? { |thing| thing == pattern }
  else
    content.any? { |thing| thing =~ pattern }
  end
end