lib/kissable/ab.rb in kissable-1.0.0a1 vs lib/kissable/ab.rb in kissable-1.0.1

- old
+ new

@@ -2,11 +2,11 @@ module Kissable class AB MAX_GROUP_COUNT = 4 - attr_reader :groups, :ratios, :test_name + attr_reader :groups, :login, :ratios, :test_name def initialize(test_name, groups=nil, ratios=nil) @test_name = test_name @groups = groups @@ -17,12 +17,14 @@ validate_groups validate_ratios end - def group(cookies) - @cookies = cookies + # Assigns a test group based on the 'abid' cookie or login (email). + # Takes either a cookies object (Hash-like) or login (String). + def group(object) + (object.is_a? String) ? (@login = object) : (@cookies = object) abset.each do |i, val| return i if val > seed end end @@ -44,10 +46,17 @@ def sha @sha ||= Digest::SHA1.hexdigest(test_name).to_i(16) end def seed - @seed ||= (sha ^ ab_cookie_value) % 100 + return @seed if @seed + + xor = @login ? login_sha : ab_cookie_value + @seed = (sha ^ xor) % 100 + end + + def login_sha + @login_sha = Digest::SHA1.hexdigest(login).to_i(16) end def abset return @abset if @abset