Class: WC::Essentials::CountTracker
- Inherits:
-
Object
- Object
- WC::Essentials::CountTracker
- Defined in:
- lib/wc/essentials/count_tracker.rb
Overview
Tracker for number of a key
Instance Method Summary collapse
-
#above(min) ⇒ Object
Return keys for item the number provider equivalent to greater than.
-
#count(key) ⇒ Object
Return count for specified key.
-
#increase(key) ⇒ Object
Increase the count for the key provided.
-
#initialize(data = {}) ⇒ CountTracker
constructor
A new instance of CountTracker.
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
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
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
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 |