Class: CanaryLabs::Resolvers::Percentage
- Inherits:
-
Object
- Object
- CanaryLabs::Resolvers::Percentage
- Defined in:
- lib/resolvers/percentage.rb
Instance Method Summary collapse
-
#initialize(percentage, beta_name) ⇒ Percentage
constructor
A new instance of Percentage.
- #participating?(id) ⇒ Boolean
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
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 |