Class: ABSwitcher::Switcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ab_switcher/switcher.rb

Constant Summary collapse

HEX_MAX =
15.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ratio, another_ratio = nil, major: true, minor: false) ⇒ Switcher

Returns a new instance of Switcher.



7
8
9
10
# File 'lib/ab_switcher/switcher.rb', line 7

def initialize(ratio, another_ratio = nil, major: true, minor: false)
  @major_probability = calc_major_probability(ratio, another_ratio)
  @major_value, @minor_value = major, minor
end

Instance Attribute Details

#major_probabilityObject (readonly)

Returns the value of attribute major_probability.



5
6
7
# File 'lib/ab_switcher/switcher.rb', line 5

def major_probability
  @major_probability
end

#major_valueObject (readonly)

Returns the value of attribute major_value.



5
6
7
# File 'lib/ab_switcher/switcher.rb', line 5

def major_value
  @major_value
end

#minor_valueObject (readonly)

Returns the value of attribute minor_value.



5
6
7
# File 'lib/ab_switcher/switcher.rb', line 5

def minor_value
  @minor_value
end

Instance Method Details

#hex_switch(hex_str) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/ab_switcher/switcher.rb', line 12

def hex_switch(hex_str)
  hex = hex_str[0].hex rescue HEX_MAX
  flt = hex / HEX_MAX

  if flt <= major_probability
    major_value
  else
    minor_value
  end
end