Class: WC::Essentials::CountTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/wc/essentials/count_tracker.rb

Overview

Tracker for number of a key

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ CountTracker

Returns a new instance of CountTracker.



8
9
10
# File 'lib/wc/essentials/count_tracker.rb', line 8

def initialize(data = {})
  @tracking = data
end

Instance Method Details

#above(min) ⇒ Object

Return keys for item the number provider equivalent to greater than

Parameters:

  • min (int)


38
39
40
# File 'lib/wc/essentials/count_tracker.rb', line 38

def above(min)
  @tracking.select { |_key, total| total > min }
end

#count(key) ⇒ Object

Return count for specified key

Parameters:

  • key (any)


27
28
29
30
31
# File 'lib/wc/essentials/count_tracker.rb', line 27

def count(key)
  return unless @tracking.key?(key)

  @tracking[key]
end

#increase(key) ⇒ Object

Increase the count for the key provided

Parameters:

  • key (any)


16
17
18
19
20
21
22
# File 'lib/wc/essentials/count_tracker.rb', line 16

def increase(key)
  @tracking ||= {}

  @tracking[key] = 0 unless @tracking.key?(key)
  @tracking[key] += 1
  self
end