Class: Kissable::AB

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

Constant Summary collapse

MAX_GROUP_COUNT =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_name, groups = nil, ratios = nil) ⇒ AB

Returns a new instance of AB.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kissable/ab.rb', line 9

def initialize(test_name, groups=nil, ratios=nil)
  @test_name = test_name

  @groups = groups
  @groups ||= %w{Original Variant}

  @ratios = ratios
  @ratios ||= [100.0 / @groups.length] * @groups.length

  validate_groups
  validate_ratios
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



7
8
9
# File 'lib/kissable/ab.rb', line 7

def groups
  @groups
end

#loginObject (readonly)

Returns the value of attribute login.



7
8
9
# File 'lib/kissable/ab.rb', line 7

def 
  @login
end

#ratiosObject (readonly)

Returns the value of attribute ratios.



7
8
9
# File 'lib/kissable/ab.rb', line 7

def ratios
  @ratios
end

#test_nameObject (readonly)

Returns the value of attribute test_name.



7
8
9
# File 'lib/kissable/ab.rb', line 7

def test_name
  @test_name
end

Instance Method Details

#cookiesObject



32
33
34
# File 'lib/kissable/ab.rb', line 32

def cookies
  @cookies ||= {}
end

#group(object) ⇒ Object

Assigns a test group based on the ‘abid’ cookie or login (email). Takes either a cookies object (Hash-like) or login (String).



24
25
26
27
28
29
30
# File 'lib/kissable/ab.rb', line 24

def group(object)
  (object.is_a? String) ? (@login = object) : (@cookies = object)

  abset.each do |i, val|
    return i if val > seed
  end
end

#tracking_script(group) ⇒ Object



36
37
38
# File 'lib/kissable/ab.rb', line 36

def tracking_script(group)
  "<script>_kmq.push(['set', {'#{test_name}' : '#{group}'}]);</script>"
end