class Blackbeard::Metric

Attributes

type[R]
type_id[R]

Public Class Methods

create(type, type_id, options = {}) click to toggle source
Calls superclass method
# File lib/blackbeard/metric.rb, line 19
def self.create(type, type_id, options = {})
  super("#{type}::#{type_id}", options)
end
find(type, type_id) click to toggle source
Calls superclass method
# File lib/blackbeard/metric.rb, line 23
def self.find(type, type_id)
  super("#{type}::#{type_id}")
end
find_or_create(type, type_id) click to toggle source
Calls superclass method
# File lib/blackbeard/metric.rb, line 27
def self.find_or_create(type, type_id)
  super("#{type}::#{type_id}")
end
new(*args) click to toggle source
Calls superclass method
# File lib/blackbeard/metric.rb, line 31
def initialize(*args)
  if args.size == 1 && args[0] =~ /::/
    @type, @type_id = args[0].split(/::/)
  elsif args.size == 2
    @type = args[0]
    @type_id = args[1]
  else
    raise ArgumentError
  end
  super("#{@type}::#{@type_id}")
end
new_from_key(key) click to toggle source
# File lib/blackbeard/metric.rb, line 43
def self.new_from_key(key)
  if key =~ /^#{master_key}::(.+)::(.+)$/
    new($1,$2)
  else
    nil
  end
end

Public Instance Methods

add(context, amount) click to toggle source
# File lib/blackbeard/metric.rb, line 59
def add(context, amount)
  uid = context.unique_identifier
  metric_data.add(uid, amount)
  group_metrics.each { |gm| gm.add(context, amount) }
  cohort_metrics.each { |cm| cm.add(context, amount) }
end
addable_cohorts() click to toggle source
# File lib/blackbeard/metric.rb, line 78
def addable_cohorts
  Cohort.all.reject{ |c| cohort_ids.include?(c.id) }
end
addable_groups() click to toggle source
# File lib/blackbeard/metric.rb, line 74
def addable_groups
  Group.all.reject{ |g| group_ids.include?(g.id) }
end
chartable_result_for_day(date) click to toggle source
# File lib/blackbeard/metric.rb, line 90
def chartable_result_for_day(date)
  metric_data.result_for_day(date)
end
chartable_result_for_hour(hour) click to toggle source
# File lib/blackbeard/metric.rb, line 86
def chartable_result_for_hour(hour)
  metric_data.result_for_hour(hour)
end
chartable_segments() click to toggle source
# File lib/blackbeard/metric.rb, line 82
def chartable_segments
  metric_data.segments
end
cohort_metrics() click to toggle source
# File lib/blackbeard/metric.rb, line 55
def cohort_metrics
  cohorts.map{ |c| CohortMetric.new(c, self) }
end
group_metrics() click to toggle source
# File lib/blackbeard/metric.rb, line 51
def group_metrics
  groups.map{ |g| GroupMetric.new(g, self) }
end
metric_data() click to toggle source
# File lib/blackbeard/metric.rb, line 66
def metric_data
  @metric_data ||= MetricData.const_get(type.capitalize).new(self, nil, nil)
end
name() click to toggle source
# File lib/blackbeard/metric.rb, line 70
def name
  storable_attributes_hash['name'] || type_id
end