Class: Ab::Tester

Inherits:
Object
  • Object
show all
Defined in:
lib/ab/tester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#chancesObject (readonly)

Returns the value of attribute chances.



3
4
5
# File 'lib/ab/tester.rb', line 3

def chances
  @chances
end

#inputObject (readonly)

Returns the value of attribute input.



3
4
5
# File 'lib/ab/tester.rb', line 3

def input
  @input
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/ab/tester.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/ab/tester.rb', line 3

def options
  @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 options[index]
  else
    return options[index]
  end
end

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/ab/tester.rb', line 15

def valid?
  chances.count == options.count
end

#validate!Object

Raises:

  • (ArgumentError)


19
20
21
# File 'lib/ab/tester.rb', line 19

def validate!
  raise ArgumentError unless valid?
end