Sha256: 41bbf0fd9769d265635b13cc5a82e4b357a26d9bad4b2598226d9d8daf1334d2

Contents?: true

Size: 558 Bytes

Versions: 2

Compression:

Stored size: 558 Bytes

Contents

require 'digest'

module CanaryLabs
  module Resolvers
    class Percentage
      def initialize(percentage, beta_name)
        @percentage = percentage
        @beta_name = beta_name
      end

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
canary_labs-0.3.0 lib/resolvers/percentage.rb
canary_labs-0.2.0 lib/resolvers/percentage.rb