Class: Roadie::Deduplicator

Inherits:
Object
  • Object
show all
Defined in:
lib/roadie/deduplicator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Deduplicator

Returns a new instance of Deduplicator.



7
8
9
10
# File 'lib/roadie/deduplicator.rb', line 7

def initialize(input)
  @input = input
  @duplicates = false
end

Class Method Details

.apply(input) ⇒ Object



3
4
5
# File 'lib/roadie/deduplicator.rb', line 3

def self.apply(input)
  new(input).apply
end

Instance Method Details

#applyObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/roadie/deduplicator.rb', line 12

def apply
  # Bail early for very small inputs
  input if input.size < 2

  calculate_latest_occurance

  # Another early bail in case we never even have a duplicate value
  if has_duplicates?
    strip_out_duplicates
  else
    input
  end
end