ab_switcher 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ab_switcher/switcher.rb +13 -29
- data/lib/ab_switcher/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50e6edf04ae56186c3ab3b9672bf799e38ab58a1df8359372ff256bd16abd5f3
|
4
|
+
data.tar.gz: 2fce66b154711a752db3784393e5ac324d32e7a7bdec908fc551071f42734ddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 245141f05c81c178702d8c01b7e6b3497edddf78e106c14abeca63573a39e656c46eadec514e623ccff9d4b329ea7cc1fee36390226bc4b8428984d2ccafbb8f
|
7
|
+
data.tar.gz: 6f2c317fec2a80ecb3974ca7485cc7fe91a1ea5e172a277f5699c0c90d00534ba6afade2538af0d8e86bda25e9fc390151bb22ba67688b9cb24185563f02269a
|
data/lib/ab_switcher/switcher.rb
CHANGED
@@ -2,52 +2,36 @@ module ABSwitcher
|
|
2
2
|
class Switcher
|
3
3
|
HEX_MAX = 15.0
|
4
4
|
|
5
|
-
attr_reader :major_probability
|
5
|
+
attr_reader :major_probability
|
6
6
|
|
7
|
-
def initialize(ratio
|
8
|
-
@major_probability = calc_major_probability(ratio
|
9
|
-
@major_value, @minor_value = major, minor
|
7
|
+
def initialize(ratio)
|
8
|
+
@major_probability = calc_major_probability(ratio)
|
10
9
|
end
|
11
10
|
|
12
|
-
def
|
13
|
-
|
14
|
-
flt = hex / HEX_MAX
|
15
|
-
|
16
|
-
if flt <= major_probability
|
17
|
-
major_value
|
18
|
-
else
|
19
|
-
minor_value
|
20
|
-
end
|
11
|
+
def major_hex?(hex_str)
|
12
|
+
hex_probability(hex_str) <= major_probability
|
21
13
|
end
|
22
14
|
|
23
15
|
private
|
24
16
|
|
25
|
-
def calc_major_probability(ratio
|
26
|
-
|
27
|
-
|
28
|
-
probability = if another_ratio.nil?
|
29
|
-
convert_ratio_into_probability(ratio)
|
30
|
-
else
|
31
|
-
calc_probability(ratio, another_ratio)
|
32
|
-
end
|
33
|
-
|
17
|
+
def calc_major_probability(ratio)
|
18
|
+
probability = convert_ratio_into_probability(ratio.to_f)
|
34
19
|
probability > 0.5 ? probability : 1 - probability
|
35
20
|
end
|
36
21
|
|
37
22
|
def convert_ratio_into_probability(ratio)
|
38
|
-
if ratio.between?(
|
39
|
-
# 1 goes here
|
40
|
-
ratio / 100
|
41
|
-
elsif ratio.between?(0, 1)
|
23
|
+
if ratio.between?(0, 1)
|
42
24
|
ratio
|
43
25
|
else
|
44
26
|
# TODO handle
|
45
|
-
raise
|
27
|
+
raise NotImplementedError
|
46
28
|
end
|
47
29
|
end
|
48
30
|
|
49
|
-
def
|
50
|
-
|
31
|
+
def hex_probability(hex_str)
|
32
|
+
# switch by first char
|
33
|
+
hex = hex_str[0].hex rescue 0
|
34
|
+
hex / HEX_MAX
|
51
35
|
end
|
52
36
|
end
|
53
37
|
end
|
data/lib/ab_switcher/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ab_switcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nishisuke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|