Class: Reth::DuplicatesFilter
- Inherits:
-
Object
- Object
- Reth::DuplicatesFilter
- Defined in:
- lib/reth/duplicates_filter.rb
Instance Method Summary collapse
- #include?(v) ⇒ Boolean
-
#initialize(max_items = 128) ⇒ DuplicatesFilter
constructor
A new instance of DuplicatesFilter.
- #update(data) ⇒ Object
Constructor Details
#initialize(max_items = 128) ⇒ DuplicatesFilter
Returns a new instance of DuplicatesFilter.
7 8 9 10 |
# File 'lib/reth/duplicates_filter.rb', line 7 def initialize(max_items=128) @max_items = max_items @filter = [] end |
Instance Method Details
#include?(v) ⇒ Boolean
23 24 25 |
# File 'lib/reth/duplicates_filter.rb', line 23 def include?(v) @filter.include?(v) end |
#update(data) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/reth/duplicates_filter.rb', line 12 def update(data) if @filter.include?(data) @filter.push @filter.shift false else @filter.push data @filter.shift if @filter.size > @max_items true end end |