Class: Ab::Test
- Inherits:
-
Struct
- Object
- Struct
- Ab::Test
- 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
-
#bucket_count ⇒ Object
Returns the value of attribute bucket_count.
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#salt ⇒ Object
Returns the value of attribute salt.
Instance Method Summary collapse
- #all_buckets? ⇒ Boolean
- #buckets ⇒ Object
- #end_at ⇒ Object
- #name ⇒ Object
- #seed ⇒ Object
- #start_at ⇒ Object
- #variants ⇒ Object
- #weight_sum ⇒ Object
Instance Attribute Details
#bucket_count ⇒ Object
Returns the value of attribute bucket_count
2 3 4 |
# File 'lib/ab/test.rb', line 2 def bucket_count @bucket_count end |
#hash ⇒ Object
Returns the value of attribute hash
2 3 4 |
# File 'lib/ab/test.rb', line 2 def hash @hash end |
#salt ⇒ Object
Returns the value of attribute salt
2 3 4 |
# File 'lib/ab/test.rb', line 2 def salt @salt end |
Instance Method Details
#all_buckets? ⇒ Boolean
10 11 12 |
# File 'lib/ab/test.rb', line 10 def all_buckets? hash['all_buckets'] end |
#buckets ⇒ Object
6 7 8 |
# File 'lib/ab/test.rb', line 6 def buckets hash['buckets'] end |
#end_at ⇒ Object
35 36 37 |
# File 'lib/ab/test.rb', line 35 def end_at @end_at ||= parse_time('end_at', DEFAULT_END_AT) end |
#name ⇒ Object
14 15 16 |
# File 'lib/ab/test.rb', line 14 def name hash['name'] end |
#seed ⇒ Object
27 28 29 |
# File 'lib/ab/test.rb', line 27 def seed hash['seed'] end |
#start_at ⇒ Object
31 32 33 |
# File 'lib/ab/test.rb', line 31 def start_at @start_at ||= parse_time('start_at', DEFAULT_START_AT) end |
#variants ⇒ Object
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_sum ⇒ Object
39 40 41 |
# File 'lib/ab/test.rb', line 39 def weight_sum variants.map(&:chance_weight).inject(:+) end |