Module: Trebuchet::Strategy::Percentable

Includes:
PerDenominationable
Included in:
Percent, VisitorPercent
Defined in:
lib/trebuchet/strategy.rb

Overview

Percentable module standardizes logic for percentage-based strategies

Instance Attribute Summary

Attributes included from PerDenominationable

#denominator, #numerator

Instance Method Summary collapse

Methods included from PerDenominationable

#initialize, #value_in_range?

Instance Method Details

#exportObject



141
142
143
# File 'lib/trebuchet/strategy.rb', line 141

def export
  super(percentage)
end

#set_range_from_options(options) ⇒ Object

must be called from initialize



124
125
126
127
128
129
130
131
132
133
# File 'lib/trebuchet/strategy.rb', line 124

def set_range_from_options(options)
  numerator =
    if options == nil || options.is_a?(Numeric)
      options.to_i
    else
      0
    end

  super(numerator: numerator, denominator: 100)
end

#to_sObject



135
136
137
138
139
# File 'lib/trebuchet/strategy.rb', line 135

def to_s
  kind = self.name == :visitor_percent ? "visitors" : "users"
  percentage_str = "#{percentage}% of #{kind}"
  "#{percentage_str}"
end