Class: Split::Trial
- Inherits:
-
Object
- Object
- Split::Trial
- Defined in:
- lib/split/trial.rb
Instance Attribute Summary collapse
-
#experiment ⇒ Object
Returns the value of attribute experiment.
-
#goals ⇒ Object
Returns the value of attribute goals.
Instance Method Summary collapse
- #alternative ⇒ Object
- #alternative=(alternative) ⇒ 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.goals = attrs[:goals].nil? ? [] : attrs[:goals] end |
Instance Attribute Details
#experiment ⇒ Object
Returns the value of attribute experiment.
3 4 5 |
# File 'lib/split/trial.rb', line 3 def experiment @experiment end |
#goals ⇒ Object
Returns the value of attribute goals.
4 5 6 |
# File 'lib/split/trial.rb', line 4 def goals @goals end |
Instance Method 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 |
#alternative=(alternative) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/split/trial.rb', line 41 def alternative=(alternative) @alternative = if alternative.kind_of?(Split::Alternative) alternative else self.experiment.alternatives.find{|a| a.name == alternative } end end |
#choose ⇒ Object
37 38 39 |
# File 'lib/split/trial.rb', line 37 def choose self.alternative = experiment.next_alternative end |
#choose! ⇒ Object
28 29 30 31 |
# File 'lib/split/trial.rb', line 28 def choose! choose record! end |
#complete! ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/split/trial.rb', line 18 def complete! if alternative if self.goals.empty? alternative.increment_completion else self.goals.each {|g| alternative.increment_completion(g)} end end end |
#record! ⇒ Object
33 34 35 |
# File 'lib/split/trial.rb', line 33 def record! alternative.increment_participation end |