Class: Bitmap::Counter
- Inherits:
-
Object
- Object
- Bitmap::Counter
- Defined in:
- lib/bitmap/counter.rb
Direct Known Subclasses
Constant Summary collapse
- VERSION =
"0.0.0"
Class Method Summary collapse
Instance Method Summary collapse
- #count(id) ⇒ Object
- #counted?(id) ⇒ Boolean
- #delete ⇒ Object
-
#initialize(name) ⇒ Counter
constructor
A new instance of Counter.
- #to_s ⇒ Object
- #unique ⇒ Object
Constructor Details
#initialize(name) ⇒ Counter
Returns a new instance of Counter.
15 16 17 |
# File 'lib/bitmap/counter.rb', line 15 def initialize(name) @name = name end |
Class Method Details
.redis ⇒ Object
10 11 12 |
# File 'lib/bitmap/counter.rb', line 10 def redis @redis ||= Redis.new end |
.redis=(connection) ⇒ Object
6 7 8 |
# File 'lib/bitmap/counter.rb', line 6 def redis=(connection) @redis = connection end |
Instance Method Details
#count(id) ⇒ Object
19 20 21 |
# File 'lib/bitmap/counter.rb', line 19 def count(id) self.class.redis.setbit(key, id, 1) end |
#counted?(id) ⇒ Boolean
23 24 25 |
# File 'lib/bitmap/counter.rb', line 23 def counted?(id) self.class.redis.getbit(key, id) == 1 end |
#delete ⇒ Object
31 32 33 |
# File 'lib/bitmap/counter.rb', line 31 def delete self.class.redis.del(key) end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/bitmap/counter.rb', line 35 def to_s bitset.to_s end |
#unique ⇒ Object
27 28 29 |
# File 'lib/bitmap/counter.rb', line 27 def unique bitset.cardinality end |