Class: Bitmap::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/bitmap/counter.rb

Direct Known Subclasses

DateCounter

Constant Summary collapse

VERSION =
"0.0.0"

Class Method Summary collapse

Instance Method Summary collapse

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

.redisObject



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

Returns:

  • (Boolean)


23
24
25
# File 'lib/bitmap/counter.rb', line 23

def counted?(id)
  self.class.redis.getbit(key, id) == 1
end

#deleteObject



31
32
33
# File 'lib/bitmap/counter.rb', line 31

def delete
  self.class.redis.del(key)
end

#to_sObject



35
36
37
# File 'lib/bitmap/counter.rb', line 35

def to_s
  bitset.to_s
end

#uniqueObject



27
28
29
# File 'lib/bitmap/counter.rb', line 27

def unique
  bitset.cardinality
end