ab-switcher 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 782a74c1b9160d87c7fda6ade34131e2c9d9ce184a1498384bb4700a503571aa
4
- data.tar.gz: 723976a688f981fceccce9b456389c9a90083de8cd12aaab4ba52be4d180683f
3
+ metadata.gz: 887013df974bf03bace0f359632b2afc41716e4e53eddde736ddb6e4614580ad
4
+ data.tar.gz: 6a8f1c0a12f33629509e334858a36d4c0a870ba847cf74ff93239b8f5c2eb35a
5
5
  SHA512:
6
- metadata.gz: 50be9898ae6a6358f5d3b159fc3f96b4fe7debad273d1f0dff27528e692dcb517ac2dcedfc15fce58c05bef7c2659187337edc669e3a189ca6b33ef5e91dc6d3
7
- data.tar.gz: 8d9539000dda7c8fd62b5a13ebdeab8f6a11eeb9a011e094603180eab9637b81501b17a5d6f8a13c6dc576d5196c0bc26c35c424fac92f465aad0e519447e5e1
6
+ metadata.gz: caedec311f23f415b6608c7d31ec6d86b73fa48405afb4edd352c9190f4fd6d4584bb9ca7247406337e1aea2fe425f515d4b724751ee25a24d7e8c422dd6660c
7
+ data.tar.gz: a8112706303c917a052a9d469d2ce31ece67446eb8146e71cebd16e271fbb66fdde30c6bd840abe1d1fc9b9be06b06676a4c84ea2420454875072fb87e650265
@@ -1,5 +1,2 @@
1
1
  require "ab_switcher/version"
2
-
3
- module ABSwitcher
4
- # Your code goes here...
5
- end
2
+ require 'ab_switcher/switcher'
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ABSwitcher
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  end
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.0
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-07 00:00:00.000000000 Z
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: