Class: OnboardOnRails::AbAssigner

Inherits:
Object
  • Object
show all
Defined in:
app/services/onboard_on_rails/ab_assigner.rb

Class Method Summary collapse

Class Method Details

.assign_group(user_id:, tour:, groups: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/onboard_on_rails/ab_assigner.rb', line 5

def self.assign_group(user_id:, tour:, groups: nil)
  return nil if tour.ab_test_id.blank?

  groups ||= OnboardOnRails::Tour
    .where(ab_test_id: tour.ab_test_id)
    .distinct
    .pluck(:ab_test_group)
    .compact

  return nil if groups.empty?

  hash = Digest::SHA256.hexdigest("#{user_id}-#{tour.ab_test_id}")
  index = hash.to_i(16) % groups.size
  groups.sort[index]
end