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.
91 92 93 |
# File 'lib/ablab.rb', line 91 def initialize(experiment, session_id) @experiment, @session_id = experiment, session_id end |
Instance Attribute Details
#experiment ⇒ Object (readonly)
Returns the value of attribute experiment.
89 90 91 |
# File 'lib/ablab.rb', line 89 def experiment @experiment end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
89 90 91 |
# File 'lib/ablab.rb', line 89 def session_id @session_id end |
Instance Method Details
#draw ⇒ Object
114 115 116 |
# File 'lib/ablab.rb', line 114 def draw Random.new(session_id.hash ^ experiment.name.hash).rand(1000) end |
#group ⇒ Object
107 108 109 110 111 112 |
# File 'lib/ablab.rb', line 107 def group return @group unless @group.nil? size = 1000.0 * (experiment.percentage_of_visitors) / 100.0 idx = (draw * experiment.groups.size / size).floor @group = experiment.groups[idx].try(:name) end |
#in_group?(name) ⇒ Boolean
95 96 97 |
# File 'lib/ablab.rb', line 95 def in_group?(name) group == name end |