Class: Ab::Tester
- Inherits:
-
Object
- Object
- Ab::Tester
- Defined in:
- lib/ab/tester.rb
Instance Attribute Summary collapse
-
#chances ⇒ Object
readonly
Returns the value of attribute chances.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(id) ⇒ Object (also: #for)
-
#initialize(opts = {}) ⇒ Tester
constructor
A new instance of Tester.
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Tester
Returns a new instance of Tester.
5 6 7 8 9 10 11 12 13 |
# File 'lib/ab/tester.rb', line 5 def initialize(opts={}) opts = defaults.merge!(opts) @options = opts[:options] @chances = Chance.new(opts[:chances]) @input = opts[:input] @indexer = opts[:indexer] @name = opts[:name] end |
Instance Attribute Details
#chances ⇒ Object (readonly)
Returns the value of attribute chances.
3 4 5 |
# File 'lib/ab/tester.rb', line 3 def chances @chances end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
3 4 5 |
# File 'lib/ab/tester.rb', line 3 def input @input end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/ab/tester.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/ab/tester.rb', line 3 def @options end |
Instance Method Details
#call(id) ⇒ Object Also known as: for
23 24 25 26 27 28 29 30 31 |
# File 'lib/ab/tester.rb', line 23 def call(id) validate! index = @indexer.call(:value=>id,:chances=>chances.to_a, :seed=>name) if block_given? yield [index] else return [index] end end |
#valid? ⇒ Boolean
15 16 17 |
# File 'lib/ab/tester.rb', line 15 def valid? chances.count == .count end |
#validate! ⇒ Object
19 20 21 |
# File 'lib/ab/tester.rb', line 19 def validate! raise ArgumentError unless valid? end |