Class: Wordlist::UniqueFilter
- Inherits:
-
Object
- Object
- Wordlist::UniqueFilter
- Defined in:
- lib/wordlist/unique_filter.rb
Overview
Acts as a filter to filter out duplicate words.
Instance Attribute Summary collapse
-
#hashes ⇒ Set<Integer>
readonly
The seen String hashes.
Instance Method Summary collapse
-
#add(word) ⇒ Object
(also: #<<)
Adds the word to the unique filter.
-
#add?(word) ⇒ Boolean
Attempts to add the word to the unique filter.
-
#clear ⇒ Object
Clears the unique filter.
-
#empty? ⇒ Boolean
Determines if the unique filter is empty or not.
-
#include?(word) ⇒ Boolean
Determines if the given word has been previously seen.
-
#initialize ⇒ UniqueFilter
constructor
Creates a new unique filter.
-
#size ⇒ Integer
The size of the unique filter.
Constructor Details
#initialize ⇒ UniqueFilter
Creates a new unique filter.
22 23 24 |
# File 'lib/wordlist/unique_filter.rb', line 22 def initialize @hashes = Set.new end |
Instance Attribute Details
#hashes ⇒ Set<Integer> (readonly)
The seen String hashes
17 18 19 |
# File 'lib/wordlist/unique_filter.rb', line 17 def hashes @hashes end |
Instance Method Details
#add(word) ⇒ Object Also known as: <<
Adds the word to the unique filter.
45 46 47 |
# File 'lib/wordlist/unique_filter.rb', line 45 def add(word) @hashes.add(word.hash) end |
#add?(word) ⇒ Boolean
Attempts to add the word to the unique filter.
61 62 63 |
# File 'lib/wordlist/unique_filter.rb', line 61 def add?(word) !@hashes.add?(word.hash).nil? end |
#clear ⇒ Object
Clears the unique filter.
77 78 79 |
# File 'lib/wordlist/unique_filter.rb', line 77 def clear @hashes.clear end |
#empty? ⇒ Boolean
Determines if the unique filter is empty or not.
70 71 72 |
# File 'lib/wordlist/unique_filter.rb', line 70 def empty? @hashes.empty? end |
#include?(word) ⇒ Boolean
Determines if the given word has been previously seen.
35 36 37 |
# File 'lib/wordlist/unique_filter.rb', line 35 def include?(word) @hashes.include?(word.hash) end |
#size ⇒ Integer
The size of the unique filter.
87 88 89 |
# File 'lib/wordlist/unique_filter.rb', line 87 def size @hashes.size end |