Class: Text::Gen::Filter::Distinct

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

Overview

Return nil if the text value has already been generated

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



8
9
10
11
12
13
14
15
# File 'lib/text/gen/filter/distinct.rb', line 8

def result(context, result)
  return result if key != context.current_key

  previous = context.remembered(key)
  return if previous.any? { |r| r.text.strip.downcase == result.text.strip.downcase }

  result
end