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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22b2df9efba9b7560b2b61c580c5a8a7c5bf6f84c9c6f851a9fd99e568cbbe03
4
- data.tar.gz: b5fb6833293878afef9cda60f96cb3d7c455b0148885553facc00fbae048a65f
3
+ metadata.gz: 50e6edf04ae56186c3ab3b9672bf799e38ab58a1df8359372ff256bd16abd5f3
4
+ data.tar.gz: 2fce66b154711a752db3784393e5ac324d32e7a7bdec908fc551071f42734ddd
5
5
  SHA512:
6
- metadata.gz: ee838852922e6d63442da72f139ce125127ad1116eafb8b7fd23a47e0e87c9240f8f6fac395dda78cd2a0d3ba01718990fc67946c4257eaa91f10b92061cecd4
7
- data.tar.gz: b3aa3a2c459e739f7d2f94b9dda139e73a115640343fac15e12a94a7cc4c5ec65f8449f1e186e3e240301f2b233d8978a7bd93cf892a2c78de0a5357a8f5d527
6
+ metadata.gz: 245141f05c81c178702d8c01b7e6b3497edddf78e106c14abeca63573a39e656c46eadec514e623ccff9d4b329ea7cc1fee36390226bc4b8428984d2ccafbb8f
7
+ data.tar.gz: 6f2c317fec2a80ecb3974ca7485cc7fe91a1ea5e172a277f5699c0c90d00534ba6afade2538af0d8e86bda25e9fc390151bb22ba67688b9cb24185563f02269a
@@ -2,52 +2,36 @@ module ABSwitcher
2
2
  class Switcher
3
3
  HEX_MAX = 15.0
4
4
 
5
- attr_reader :major_probability, :major_value, :minor_value
5
+ attr_reader :major_probability
6
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
7
+ def initialize(ratio)
8
+ @major_probability = calc_major_probability(ratio)
10
9
  end
11
10
 
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
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, 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
-
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?(1, 100)
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 DOUSHIYOU
27
+ raise NotImplementedError
46
28
  end
47
29
  end
48
30
 
49
- def calc_probability(ratio, another_ratio)
50
- ratio / (ratio + another_ratio)
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
@@ -1,3 +1,3 @@
1
1
  module ABSwitcher
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
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.2
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-08 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler