Class: Text::Gen::Filter::Exclude

Inherits:
Base
  • Object
show all
Defined in:
lib/text/gen/filter/exclude.rb

Overview

Exclude is the opposite of ‘match` and returns nil if the result metadata is matches the pattern in this filter.

Instance Method Summary collapse

Methods inherited from Base

#component_key, filter_key, filter_name, #initialize, #key, #to_s, #type, #value

Constructor Details

This class inherits a constructor from Text::Gen::Filter::Base

Instance Method Details

#result(context, result) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/text/gen/filter/exclude.rb', line 9

def result(context, result)
  return result if @depth && context.depth != @depth
  return if result.nil?
  return if value == "*" && result.meta.key?(key)
  return if key == "*" && result.meta.values.any? { |arr| arr.include?(value) }
  return if result.meta[key]&.include?(value)

  result
end