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.
- #perform_callbacks!(event) ⇒ Object
- #track_success! ⇒ Object
- #track_view! ⇒ Object
Constructor Details
#initialize(experiment, session_id) ⇒ Run
Returns a new instance of Run.
96 97 98 |
# File 'lib/ablab.rb', line 96 def initialize(experiment, session_id) @experiment, @session_id = experiment, session_id end |
Instance Attribute Details
#experiment ⇒ Object (readonly)
Returns the value of attribute experiment.
94 95 96 |
# File 'lib/ablab.rb', line 94 def experiment @experiment end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
94 95 96 |
# File 'lib/ablab.rb', line 94 def session_id @session_id end |
Instance Method Details
#draw ⇒ Object
121 122 123 124 125 |
# File 'lib/ablab.rb', line 121 def draw sid_hash = Digest::SHA1.hexdigest(session_id)[-8..-1].to_i(16) exp_hash = Digest::SHA1.hexdigest(experiment.name.to_s)[-8..-1].to_i(16) (sid_hash ^ exp_hash) % 1000 end |
#group ⇒ Object
114 115 116 117 118 119 |
# File 'lib/ablab.rb', line 114 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
100 101 102 |
# File 'lib/ablab.rb', line 100 def in_group?(name) group == name end |
#perform_callbacks!(event) ⇒ Object
127 128 129 130 131 |
# File 'lib/ablab.rb', line 127 def perform_callbacks!(event) experiment.callbacks.each do |cbk| cbk.call(event, experiment.name, group, session_id) end end |