ab-switcher 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ab_switcher.rb +1 -4
- data/lib/ab_switcher/switcher.rb +53 -0
- data/lib/ab_switcher/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 887013df974bf03bace0f359632b2afc41716e4e53eddde736ddb6e4614580ad
|
4
|
+
data.tar.gz: 6a8f1c0a12f33629509e334858a36d4c0a870ba847cf74ff93239b8f5c2eb35a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caedec311f23f415b6608c7d31ec6d86b73fa48405afb4edd352c9190f4fd6d4584bb9ca7247406337e1aea2fe425f515d4b724751ee25a24d7e8c422dd6660c
|
7
|
+
data.tar.gz: a8112706303c917a052a9d469d2ce31ece67446eb8146e71cebd16e271fbb66fdde30c6bd840abe1d1fc9b9be06b06676a4c84ea2420454875072fb87e650265
|
data/lib/ab_switcher.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
module ABSwitcher
|
2
|
+
class Switcher
|
3
|
+
HEX_MAX = 15.0
|
4
|
+
|
5
|
+
attr_reader :major_probability, :major_value, :minor_value
|
6
|
+
|
7
|
+
def initialize(ratio, another_ratio = nil, major: true, minor: false)
|
8
|
+
@major_probability = calc_major_probability(ratio, another_ratio)
|
9
|
+
@major_value, @minor_value = major, minor
|
10
|
+
end
|
11
|
+
|
12
|
+
def hex_switch(hex_str)
|
13
|
+
hex = hex_str[0].hex rescue HEX_MAX
|
14
|
+
flt = hex / HEX_MAX
|
15
|
+
|
16
|
+
if flt <= major_probability
|
17
|
+
major_value
|
18
|
+
else
|
19
|
+
minor_value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def calc_major_probability(ratio, another_ratio = nil)
|
26
|
+
ratio = ratio.to_f
|
27
|
+
|
28
|
+
probability = if another_ratio.nil?
|
29
|
+
convert_ratio_into_probability(ratio)
|
30
|
+
else
|
31
|
+
calc_probability(ratio, another_ratio)
|
32
|
+
end
|
33
|
+
|
34
|
+
probability > 0.5 ? probability : 1 - probability
|
35
|
+
end
|
36
|
+
|
37
|
+
def convert_ratio_into_probability(ratio)
|
38
|
+
if ratio.between?(1, 100)
|
39
|
+
# 1 goes here
|
40
|
+
ratio / 100
|
41
|
+
elsif ratio.between?(0, 1)
|
42
|
+
ratio
|
43
|
+
else
|
44
|
+
# TODO handle
|
45
|
+
raise DOUSHIYOU
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def calc_probability(ratio, another_ratio)
|
50
|
+
ratio / (ratio + another_ratio)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
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.1
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- bin/console
|
70
70
|
- bin/setup
|
71
71
|
- lib/ab_switcher.rb
|
72
|
+
- lib/ab_switcher/switcher.rb
|
72
73
|
- lib/ab_switcher/version.rb
|
73
74
|
homepage: https://github.com/nishisuke/ab-switcher
|
74
75
|
licenses:
|