Class: Absurdity::Metric
- Inherits:
-
Object
- Object
- Absurdity::Metric
- Defined in:
- lib/absurdity/metric.rb
Defined Under Namespace
Classes: NotFoundError
Instance Attribute Summary collapse
-
#experiment_slug ⇒ Object
readonly
Returns the value of attribute experiment_slug.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#variant_slug ⇒ Object
readonly
Returns the value of attribute variant_slug.
Class Method Summary collapse
- .create(slug, experiment_slug, variant_slug = nil) ⇒ Object
- .find(slug, experiment_slug, variant_slug = nil) ⇒ Object
Instance Method Summary collapse
- #==(other_metric) ⇒ Object
- #count ⇒ Object
-
#initialize(slug, experiment_slug, variant_slug = nil) ⇒ Metric
constructor
A new instance of Metric.
- #save ⇒ Object
- #track! ⇒ Object
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_slug ⇒ Object (readonly)
Returns the value of attribute experiment_slug.
19 20 21 |
# File 'lib/absurdity/metric.rb', line 19 def experiment_slug @experiment_slug end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
19 20 21 |
# File 'lib/absurdity/metric.rb', line 19 def slug @slug end |
#variant_slug ⇒ Object (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
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 |
#count ⇒ Object
35 36 37 |
# File 'lib/absurdity/metric.rb', line 35 def count @count ||= 0 end |
#track! ⇒ Object
30 31 32 33 |
# File 'lib/absurdity/metric.rb', line 30 def track! @count += 1 save end |