Class: Ablab::Run
- Inherits:
-
Object
- Object
- Ablab::Run
- Defined in:
- lib/ablab.rb
Instance Attribute Summary collapse
-
#experiment ⇒ Object
readonly
Returns the value of attribute experiment.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
Instance Method Summary collapse
- #draw ⇒ Object
- #group ⇒ Object
- #in_group?(name) ⇒ Boolean
-
#initialize(experiment, session_id) ⇒ Run
constructor
A new instance of Run.
- #track_success! ⇒ Object
- #track_view! ⇒ Object
Constructor Details
#initialize(experiment, session_id) ⇒ Run
Returns a new instance of Run.
86 87 88 89 |
# File 'lib/ablab.rb', line 86 def initialize(experiment, session_id) @experiment, @session_id = experiment, session_id @experiment = experiment end |
Instance Attribute Details
#experiment ⇒ Object (readonly)
Returns the value of attribute experiment.
84 85 86 |
# File 'lib/ablab.rb', line 84 def experiment @experiment end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
84 85 86 |
# File 'lib/ablab.rb', line 84 def session_id @session_id end |
Instance Method Details
#draw ⇒ Object
109 110 111 |
# File 'lib/ablab.rb', line 109 def draw Random.new(session_id.hash ^ experiment.name.hash).rand(1000) end |
#group ⇒ Object
103 104 105 106 107 |
# File 'lib/ablab.rb', line 103 def group return @group unless @group.nil? idx = (draw / (1000.0 / experiment.groups.size)).floor @group = experiment.groups[idx].name end |
#in_group?(name) ⇒ Boolean
91 92 93 |
# File 'lib/ablab.rb', line 91 def in_group?(name) group == name end |