Class: Bitmap::DateCounter

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

Constant Summary

Constants inherited from Counter

Counter::VERSION

Instance Method Summary collapse

Methods inherited from Counter

#initialize, redis, redis=, #to_s

Constructor Details

This class inherits a constructor from Bitmap::Counter

Instance Method Details

#count(id, date = Date.today) ⇒ Object



3
4
5
# File 'lib/bitmap/date_counter.rb', line 3

def count(id, date = Date.today)
  self.class.redis.setbit(key(date), id, 1)
end

#counted?(id, date = Date.today) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/bitmap/date_counter.rb', line 7

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

#deleteObject



22
23
24
25
26
27
28
29
# File 'lib/bitmap/date_counter.rb', line 22

def delete
  keys = self.class.redis.keys("#{prefix}*")
  self.class.redis.pipelined do
    keys.each do |k|
      self.class.redis.del(k)
    end
  end
end

#unique(range = [Date.today]) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/bitmap/date_counter.rb', line 11

def unique(range = [Date.today])
  range = [range] if range.is_a?(Date)
  set = nil
  range.each do |date|
    next unless s = bitset(date)
    set ||= s
    set |= s
  end
  set.cardinality
end