Class: CanaryLabs::Resolvers::Percentage

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

Instance Method Summary collapse

Constructor Details

#initialize(percentage, beta_name) ⇒ Percentage

Returns a new instance of Percentage.



6
7
8
9
# File 'lib/resolvers/percentage.rb', line 6

def initialize(percentage, beta_name)
  @percentage = percentage
  @beta_name = beta_name
end

Instance Method Details

#participating?(id) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# File 'lib/resolvers/percentage.rb', line 11

def participating? id
  # create a deterministic number based on the item identifier and
  # name of the beta. This will evenly distribute exposure to beta's
  # across all ID's.
  determ_num = Digest::MD5.hexdigest(id.to_s + @beta_name.to_s).to_i(16)
  (determ_num % (@percentage * 100).to_i).zero?
end