Class: Strategy

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_sdk/strategy.rb

Overview

handles the calculation of rollout for a given context

Instance Method Summary collapse

Constructor Details

#initialize(percentage) ⇒ Strategy

Returns a new instance of Strategy.



5
6
7
8
# File 'lib/ruby_sdk/strategy.rb', line 5

def initialize(percentage)
  @percentage = percentage
  @modulus = 100
end

Instance Method Details

#calculate(context) ⇒ Object



10
11
12
13
14
# File 'lib/ruby_sdk/strategy.rb', line 10

def calculate(context)
  key = context.get_key
  hashed_percentage = get_hash_based_percentage(key)
  return hashed_percentage <= @percentage
end

#get_hash_based_percentage(string) ⇒ Object



16
17
18
19
# File 'lib/ruby_sdk/strategy.rb', line 16

def get_hash_based_percentage(string) 
  sum = string.bytes.sum()
  return ((sum % @modulus) + 1)
end