Class: Afterburn::ListMetric

Inherits:
Object
  • Object
show all
Includes:
Redis::Objects
Defined in:
lib/afterburn/list_metric.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list, timestamp = Time.now) ⇒ ListMetric

Returns a new instance of ListMetric.



25
26
27
28
# File 'lib/afterburn/list_metric.rb', line 25

def initialize(list, timestamp = Time.now)
  @list = list
  @timestamp = timestamp
end

Instance Attribute Details

#timestampObject (readonly)

Returns the value of attribute timestamp.



9
10
11
# File 'lib/afterburn/list_metric.rb', line 9

def timestamp
  @timestamp
end

Class Method Details

.for_list(list, timestamps) ⇒ Object



16
17
18
# File 'lib/afterburn/list_metric.rb', line 16

def self.for_list(list, timestamps)
  timestamps.map { |timestamp| new(list, timestamp) }
end

.for_timestamp(lists, timestamp) ⇒ Object



12
13
14
# File 'lib/afterburn/list_metric.rb', line 12

def self.for_timestamp(lists, timestamp)
  lists.map { |list| new(list, timestamp) }      
end

.timestamp_count_vector(list, timestamps) ⇒ Object

TODO test



21
22
23
# File 'lib/afterburn/list_metric.rb', line 21

def self.timestamp_count_vector(list, timestamps)
  Vector[*for_list(list, timestamps).map { |metric| metric.card_count.to_i }]
end

Instance Method Details

#count!Object



34
35
36
# File 'lib/afterburn/list_metric.rb', line 34

def count!
  card_count.incr(@list.card_count)
end

#idObject



30
31
32
# File 'lib/afterburn/list_metric.rb', line 30

def id
  @id ||= Base64.encode64("#{@list.id}:#{@timestamp.to_i}")
end