Class: Ablab::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/ablab.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#experimentObject (readonly)

Returns the value of attribute experiment.



89
90
91
# File 'lib/ablab.rb', line 89

def experiment
  @experiment
end

#session_idObject (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

#drawObject



114
115
116
# File 'lib/ablab.rb', line 114

def draw
  Random.new(session_id.hash ^ experiment.name.hash).rand(1000)
end

#groupObject



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

Returns:

  • (Boolean)


95
96
97
# File 'lib/ablab.rb', line 95

def in_group?(name)
  group == name
end

#track_success!Object



103
104
105
# File 'lib/ablab.rb', line 103

def track_success!
  Ablab.tracker.track_success!(experiment.name, group, session_id)
end

#track_view!Object



99
100
101
# File 'lib/ablab.rb', line 99

def track_view!
  Ablab.tracker.track_view!(experiment.name, group, session_id)
end