Class: CQL::ContentMatchFilter
- Inherits:
-
Object
- Object
- CQL::ContentMatchFilter
- Defined in:
- lib/cql/filters.rb
Overview
Not a part of the public API. Subject to change at any time.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Pattern to match.
Instance Method Summary collapse
-
#content_match?(content) ⇒ Boolean
Returns whether or not the content matches the pattern.
-
#initialize(pattern) ⇒ ContentMatchFilter
constructor
Creates a new filter.
Constructor Details
#initialize(pattern) ⇒ ContentMatchFilter
Creates a new filter
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
#pattern ⇒ Object (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
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 |