Module: Trebuchet::Strategy::PerDenominationable
- Included in:
- PerDenomination, Percentable
- Defined in:
- lib/trebuchet/strategy.rb
Instance Attribute Summary collapse
-
#denominator ⇒ Object
readonly
Returns the value of attribute denominator.
-
#numerator ⇒ Object
readonly
Returns the value of attribute numerator.
Instance Method Summary collapse
- #export ⇒ Object
- #initialize(options) ⇒ Object
-
#set_range_from_options(options) ⇒ Object
must be called from initialize.
- #to_s ⇒ Object
- #value_in_range?(value) ⇒ Boolean
Instance Attribute Details
#denominator ⇒ Object (readonly)
Returns the value of attribute denominator.
81 82 83 |
# File 'lib/trebuchet/strategy.rb', line 81 def denominator @denominator end |
#numerator ⇒ Object (readonly)
Returns the value of attribute numerator.
81 82 83 |
# File 'lib/trebuchet/strategy.rb', line 81 def numerator @numerator end |
Instance Method Details
#export ⇒ Object
111 112 113 |
# File 'lib/trebuchet/strategy.rb', line 111 def export super({ numerator: numerator, denominator: denominator }) end |
#initialize(options) ⇒ Object
83 84 85 |
# File 'lib/trebuchet/strategy.rb', line 83 def initialize() () end |
#set_range_from_options(options) ⇒ Object
must be called from initialize
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/trebuchet/strategy.rb', line 88 def () raise ArgumentError, "Missing required input numerator" unless [:numerator] raise ArgumentError, "Missing required input denominator" unless [:denominator] @numerator = [:numerator].to_i @denominator = [:denominator].to_i raise ArgumentError, "Invalid denominator #{@denominator}" if @denominator <= 0 if @numerator > @denominator raise ArgumentError, "Invalid numerator #{@numerator} > denominator #{@denominator}" end end |
#to_s ⇒ Object
107 108 109 |
# File 'lib/trebuchet/strategy.rb', line 107 def to_s "#{numerator} / #{denominator} of users" end |
#value_in_range?(value) ⇒ Boolean
101 102 103 104 105 |
# File 'lib/trebuchet/strategy.rb', line 101 def value_in_range?(value) bucket = Trebuchet::SHA1.hexdigest("#{@feature.name}|#{value}").to_i(16) % denominator bucket < numerator end |