Class: Ab::Test

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

Constant Summary collapse

DEFAULT_START_AT =
DateTime.new(0)
DEFAULT_END_AT =
DateTime.new(3000)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bucket_countObject

Returns the value of attribute bucket_count

Returns:

  • (Object)

    the current value of bucket_count



2
3
4
# File 'lib/ab/test.rb', line 2

def bucket_count
  @bucket_count
end

#hashObject

Returns the value of attribute hash

Returns:

  • (Object)

    the current value of hash



2
3
4
# File 'lib/ab/test.rb', line 2

def hash
  @hash
end

#saltObject

Returns the value of attribute salt

Returns:

  • (Object)

    the current value of salt



2
3
4
# File 'lib/ab/test.rb', line 2

def salt
  @salt
end

Instance Method Details

#all_buckets?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/ab/test.rb', line 10

def all_buckets?
  hash['all_buckets']
end

#bucketsObject



6
7
8
# File 'lib/ab/test.rb', line 6

def buckets
  hash['buckets']
end

#end_atObject



35
36
37
# File 'lib/ab/test.rb', line 35

def end_at
  @end_at ||= parse_time('end_at', DEFAULT_END_AT)
end

#nameObject



14
15
16
# File 'lib/ab/test.rb', line 14

def name
  hash['name']
end

#seedObject



27
28
29
# File 'lib/ab/test.rb', line 27

def seed
  hash['seed']
end

#start_atObject



31
32
33
# File 'lib/ab/test.rb', line 31

def start_at
  @start_at ||= parse_time('start_at', DEFAULT_START_AT)
end

#variantsObject



18
19
20
21
22
23
24
25
# File 'lib/ab/test.rb', line 18

def variants
  @variants ||= begin
    accumulated = 0
    hash['variants'].map do |variant_hash|
      Variant.new(variant_hash, accumulated += variant_hash['chance_weight'])
    end
  end
end

#weight_sumObject



39
40
41
# File 'lib/ab/test.rb', line 39

def weight_sum
  variants.map(&:chance_weight).inject(:+)
end