Class: Shamu::Features::Conditions::Percentage

Inherits:
Condition
  • Object
show all
Defined in:
lib/shamu/features/conditions/percentage.rb

Overview

Match against a limited percentage of total users.

Instance Method Summary collapse

Methods inherited from Condition

create, #initialize

Constructor Details

This class inherits a constructor from Shamu::Features::Conditions::Condition

Instance Method Details

#match?(context) ⇒ Boolean

Returns true if the condition matches the given environment.

Parameters:

  • context (Context)

    the feature evaluation context.

Returns:

  • (Boolean)

    true if the condition matches the given environment.



11
12
13
14
15
16
17
18
# File 'lib/shamu/features/conditions/percentage.rb', line 11

def match?( context )
  if context.user_id
    ( user_id_hash( context.user_id ) ^ toggle_crc ) % 100 < percentage
  else
    context.sticky!
    Random.rand( 100 ) < percentage
  end
end