flirt_checker 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/flirt_checker/blood.rb +29 -15
- data/lib/flirt_checker/version.rb +1 -1
- data/spec/flirt_checker_spec.rb +43 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 125c56f68d11fc1b98238b555287dffcf4a4d90d
|
4
|
+
data.tar.gz: 6be73395db0eb26e98c924e7c155fbe6eac300d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a311e572781a760668e39382dd142996e1ba73b1d10a9bb7e10927f86ba93e40d23c9f0babf4f7d6a0c315c03f493f4f09b078053bcc6c615fcd3429b452de0
|
7
|
+
data.tar.gz: 3fedb98e08cded5173e6f01d121e954ab7fe3cad816ecae261bf17ba111b253933237ebb30cebcd5c3951f41ba9fa482ce8b002a0d4d458c025a62f1110bd942
|
data/lib/flirt_checker/blood.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
module FlirtChecker
|
2
|
+
|
3
|
+
module Pheno
|
4
|
+
refine String do
|
5
|
+
def to_phenotype
|
6
|
+
self[-1] == "O" ? self[0] : self.squeeze
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
2
11
|
class Blood
|
12
|
+
using Pheno
|
13
|
+
|
3
14
|
BLOOD_GROUP = {
|
4
15
|
a: ["A","A","A","O"],
|
5
16
|
b: ["B","B","B","O"],
|
@@ -15,31 +26,34 @@ module FlirtChecker
|
|
15
26
|
@genotype = genotype
|
16
27
|
end
|
17
28
|
|
29
|
+
def male
|
30
|
+
@male.downcase.to_sym
|
31
|
+
end
|
32
|
+
|
33
|
+
def female
|
34
|
+
@female.downcase.to_sym
|
35
|
+
end
|
36
|
+
|
18
37
|
def combo
|
19
|
-
|
20
|
-
collection = BLOOD_GROUP[@male].product(BLOOD_GROUP[@female]).map {|e|
|
21
|
-
e.sort.join
|
22
|
-
}.uniq
|
23
|
-
#phenotype
|
24
|
-
collection.map! { |e| to_phenotype(e) } unless @genotype
|
25
|
-
collection
|
38
|
+
combo_with_rate.keys
|
26
39
|
end
|
27
40
|
|
28
41
|
def combo_with_rate
|
29
|
-
|
30
|
-
|
31
|
-
hash
|
32
|
-
hash.each_with_object({}) { |(k,v), h| h[k] = v.to_f / array.size.to_f }
|
42
|
+
c = combination
|
43
|
+
hash = c.reduce(Hash.new(0)){ |h,v| h[@genotype ? v : v.to_phenotype] += 1; h }
|
44
|
+
hash.each_with_object({}) { |(k,v), h| h[k] = v.to_f / c.size }
|
33
45
|
end
|
34
46
|
|
35
|
-
|
47
|
+
private
|
36
48
|
|
37
|
-
def
|
38
|
-
|
49
|
+
def combination
|
50
|
+
#parameterize
|
51
|
+
valid_blood_type?
|
52
|
+
BLOOD_GROUP[male].product(BLOOD_GROUP[female]).map { |e| e.sort.join }
|
39
53
|
end
|
40
54
|
|
41
55
|
def valid_blood_type?
|
42
|
-
raise ArgumentError, "Invalid Blood Type" unless BLOOD_GROUP.key?(
|
56
|
+
raise ArgumentError, "Invalid Blood Type" unless BLOOD_GROUP.key?(male) && BLOOD_GROUP.key?(female)
|
43
57
|
end
|
44
58
|
end
|
45
59
|
end
|
data/spec/flirt_checker_spec.rb
CHANGED
@@ -11,6 +11,12 @@ describe FlirtChecker do
|
|
11
11
|
expect(blood.combo).to eql(expected)
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'returns a uniq combination in phenotype' do
|
15
|
+
expected = ["A", "O"]
|
16
|
+
blood = FlirtChecker.new(:a,:a)
|
17
|
+
expect(blood.combo).to eql(expected)
|
18
|
+
end
|
19
|
+
|
14
20
|
it 'returns a combination in genotype' do
|
15
21
|
expected = ["AB", "AO", "BO", "OO"]
|
16
22
|
blood = FlirtChecker.new(:a, :b, genotype: true)
|
@@ -19,7 +25,7 @@ describe FlirtChecker do
|
|
19
25
|
|
20
26
|
it 'returns a combination with rate in phenotype' do
|
21
27
|
expected = {"AB"=>0.5625, "A"=>0.1875, "B"=>0.1875, "O"=>0.0625}
|
22
|
-
blood = FlirtChecker.new(:a, :b)
|
28
|
+
blood = FlirtChecker.new(:a, :b, genotype: false)
|
23
29
|
expect(blood.combo_with_rate).to eql(expected)
|
24
30
|
end
|
25
31
|
|
@@ -30,7 +36,7 @@ describe FlirtChecker do
|
|
30
36
|
end
|
31
37
|
|
32
38
|
it 'chenges the value of attributes' do
|
33
|
-
blood = FlirtChecker.new(:a, :
|
39
|
+
blood = FlirtChecker.new(:a, :B, genotype: true)
|
34
40
|
expect(blood.male = :b).to eql(:b)
|
35
41
|
expect(blood.female = :a).to eql(:a)
|
36
42
|
expect(blood.genotype = false).to be_falsey
|
@@ -51,8 +57,42 @@ describe FlirtChecker do
|
|
51
57
|
expect { blood.combo }.not_to raise_error
|
52
58
|
end
|
53
59
|
|
54
|
-
it 'does not
|
60
|
+
it 'does not raise exception when combo_with_rate called' do
|
55
61
|
blood = FlirtChecker.new(:a, :b)
|
56
62
|
expect { blood.combo_with_rate }.not_to raise_error
|
57
63
|
end
|
64
|
+
|
65
|
+
it 'accepts upper case strings' do
|
66
|
+
expected = ["AB", "AO", "BO", "OO"]
|
67
|
+
blood = FlirtChecker.new("A", "B", genotype: true)
|
68
|
+
expect(blood.combo).to eql(expected)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'accepts lower case strings' do
|
72
|
+
expected = ["AB", "AO", "BO", "OO"]
|
73
|
+
blood = FlirtChecker.new("a", "b", genotype: true)
|
74
|
+
expect(blood.combo).to eql(expected)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'accepts upper case symbols' do
|
78
|
+
expected = ["AB", "AO", "BO", "OO"]
|
79
|
+
blood = FlirtChecker.new(:A, :B, genotype: true)
|
80
|
+
expect(blood.combo).to eql(expected)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'does not raise exception by colling combo when an attribute updated' do
|
84
|
+
expected = ["A", "O"]
|
85
|
+
blood = FlirtChecker.new(:a,:a)
|
86
|
+
blood.male = :A
|
87
|
+
blood.female = :a
|
88
|
+
expect(blood.combo).to eql(expected)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'does not raise exception by colling combo_with_rate when an attribute updated' do
|
92
|
+
expected = {"B"=>0.9375, "O"=>0.0625}
|
93
|
+
blood = FlirtChecker.new(:b,:b)
|
94
|
+
blood.male = "B"
|
95
|
+
blood.female = "b"
|
96
|
+
expect(blood.combo_with_rate).to eql(expected)
|
97
|
+
end
|
58
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flirt_checker
|
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
|
- tacyan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|