Class: Absurdity::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/absurdity/metric.rb

Defined Under Namespace

Classes: NotFoundError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slug, experiment_slug, variant_slug = nil) ⇒ Metric

Returns a new instance of Metric.



20
21
22
23
24
# File 'lib/absurdity/metric.rb', line 20

def initialize(slug, experiment_slug, variant_slug=nil)
  @slug            = slug
  @experiment_slug = experiment_slug
  @variant_slug    = variant_slug
end

Instance Attribute Details

#experiment_slugObject (readonly)

Returns the value of attribute experiment_slug.



19
20
21
# File 'lib/absurdity/metric.rb', line 19

def experiment_slug
  @experiment_slug
end

#slugObject (readonly)

Returns the value of attribute slug.



19
20
21
# File 'lib/absurdity/metric.rb', line 19

def slug
  @slug
end

#variant_slugObject (readonly)

Returns the value of attribute variant_slug.



19
20
21
# File 'lib/absurdity/metric.rb', line 19

def variant_slug
  @variant_slug
end

Class Method Details

.create(slug, experiment_slug, variant_slug = nil) ⇒ Object



5
6
7
8
9
# File 'lib/absurdity/metric.rb', line 5

def self.create(slug, experiment_slug, variant_slug=nil)
  metric = new(slug, experiment_slug, variant_slug)
  metric.save
  metric
end

.find(slug, experiment_slug, variant_slug = nil) ⇒ Object

Raises:



11
12
13
14
15
16
17
# File 'lib/absurdity/metric.rb', line 11

def self.find(slug, experiment_slug, variant_slug=nil)
  raise NotFoundError unless metric = Datastore.find(self,
                                                     slug:            slug,
                                                     experiment_slug: experiment_slug,
                                                     variant_slug:    variant_slug)
  metric
end

Instance Method Details

#==(other_metric) ⇒ Object



39
40
41
42
43
# File 'lib/absurdity/metric.rb', line 39

def ==(other_metric)
  slug            == other_metric.slug            &&
  experiment_slug == other_metric.experiment_slug &&
  variant_slug    == other_metric.variant_slug
end

#countObject



35
36
37
# File 'lib/absurdity/metric.rb', line 35

def count
  @count ||= 0
end

#saveObject



26
27
28
# File 'lib/absurdity/metric.rb', line 26

def save
  Datastore.save(self)
end

#track!Object



30
31
32
33
# File 'lib/absurdity/metric.rb', line 30

def track!
  @count += 1
  save
end