Class: Kissable::AB
- Inherits:
-
Object
- Object
- Kissable::AB
- Defined in:
- lib/kissable/ab.rb
Constant Summary collapse
- MAX_GROUP_COUNT =
4
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#ratios ⇒ Object
readonly
Returns the value of attribute ratios.
-
#test_name ⇒ Object
readonly
Returns the value of attribute test_name.
Instance Method Summary collapse
- #cookies ⇒ Object
-
#group(object) ⇒ Object
Assigns a test group based on the ‘abid’ cookie or login (email).
-
#initialize(test_name, groups = nil, ratios = nil) ⇒ AB
constructor
A new instance of AB.
- #tracking_script(group) ⇒ Object
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
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
7 8 9 |
# File 'lib/kissable/ab.rb', line 7 def groups @groups end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
7 8 9 |
# File 'lib/kissable/ab.rb', line 7 def login @login end |
#ratios ⇒ Object (readonly)
Returns the value of attribute ratios.
7 8 9 |
# File 'lib/kissable/ab.rb', line 7 def ratios @ratios end |
#test_name ⇒ Object (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
#cookies ⇒ Object
32 33 34 |
# File 'lib/kissable/ab.rb', line 32 def @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 |