Class: Split::Trial
- Inherits:
-
Object
- Object
- Split::Trial
- Defined in:
- lib/split/trial.rb
Instance Attribute Summary collapse
- #alternative ⇒ Object
-
#experiment ⇒ Object
Returns the value of attribute experiment.
Instance Method Summary collapse
- #alternative_name=(name) ⇒ Object
- #choose ⇒ Object
- #choose! ⇒ Object
- #complete! ⇒ Object
-
#initialize(attrs = {}) ⇒ Trial
constructor
A new instance of Trial.
- #record! ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Trial
Returns a new instance of Trial.
6 7 8 9 10 |
# File 'lib/split/trial.rb', line 6 def initialize(attrs = {}) self.experiment = attrs[:experiment] if !attrs[:experiment].nil? self.alternative = attrs[:alternative] if !attrs[:alternative].nil? self.alternative_name = attrs[:alternative_name] if !attrs[:alternative_name].nil? end |
Instance Attribute Details
#alternative ⇒ Object
12 13 14 15 16 |
# File 'lib/split/trial.rb', line 12 def alternative @alternative ||= if experiment.winner experiment.winner end end |
#experiment ⇒ Object
Returns the value of attribute experiment.
3 4 5 |
# File 'lib/split/trial.rb', line 3 def experiment @experiment end |
Instance Method Details
#alternative_name=(name) ⇒ Object
39 40 41 |
# File 'lib/split/trial.rb', line 39 def alternative_name=(name) self.alternative= self.experiment.alternatives.find{|a| a.name == name } end |
#choose ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/split/trial.rb', line 31 def choose if experiment.winner self.alternative = experiment.winner else self.alternative = experiment.next_alternative end end |
#choose! ⇒ Object
22 23 24 25 |
# File 'lib/split/trial.rb', line 22 def choose! choose record! end |
#complete! ⇒ Object
18 19 20 |
# File 'lib/split/trial.rb', line 18 def complete! alternative.increment_completion if alternative end |
#record! ⇒ Object
27 28 29 |
# File 'lib/split/trial.rb', line 27 def record! alternative.increment_participation end |