class CQL::ContentMatchFilter

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

Attributes

pattern[R]

Pattern to match

Public Class Methods

new(pattern) click to toggle source

Creates a new filter

# 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

Public Instance Methods

content_match?(content) click to toggle source

Returns whether or not the content matches the pattern

# 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