tennis 0.1.1 → 0.1.2
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/Makefile +9 -0
- data/lib/tennis/version.rb +1 -1
- data/lib/tennis.rb +14 -10
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f6e209d9196cecd2a9e47953f230d89d63496aae
|
|
4
|
+
data.tar.gz: d5bd1a1d77ecc2d243207bb6cd8315a53fd1d54a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 754ce0601818ee8e17e4222b8fb31884a1b6f00fb2d2c5500e967fe16ae0f6c583d4c5c71d731e524be9e2a49af97905c0f1b18cac6ef2249eca35b69263d0bb
|
|
7
|
+
data.tar.gz: 1f3c1371982bdcccf50d37ba8f8967182e02e94c4995eac80f20ec3d1efd9f1d324dfc489beebb559ce608ea628f1cb35ac9ccc6100081f142a04f9c3c7dcef3
|
data/Makefile
ADDED
data/lib/tennis/version.rb
CHANGED
data/lib/tennis.rb
CHANGED
|
@@ -11,9 +11,9 @@ class Tennis
|
|
|
11
11
|
validation_1 = @scores.length == 2
|
|
12
12
|
# to check if any input > 7
|
|
13
13
|
validation_2 = @scores.any? { |score| score > 7 }
|
|
14
|
-
# to check if one of the input is 7 and the other is not 6
|
|
14
|
+
# to check if one of the input is 7 and the other is not 6
|
|
15
15
|
# bad tie break input
|
|
16
|
-
validation_3 = false
|
|
16
|
+
validation_3 = false
|
|
17
17
|
@scores.each_slice(2).each {|r| validation_3 = true if r.any? {|score| score == 7} && !r.any? {|score| score == 6} }
|
|
18
18
|
@result = :error if validation_1 || validation_2 || validation_3
|
|
19
19
|
# if set score is not complete eg: 4-6,7-6,4-1
|
|
@@ -21,20 +21,24 @@ class Tennis
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
#
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
# to_s
|
|
25
|
+
# return the score in string format
|
|
26
|
+
def to_s
|
|
27
|
+
score = []
|
|
28
|
+
(0...@scores.length).step(2).each do |i|
|
|
29
|
+
score << [@scores[i], @scores[i+1]].join('-')
|
|
30
|
+
end
|
|
31
|
+
score.join(', ')
|
|
27
32
|
end
|
|
28
33
|
|
|
29
34
|
# flip score ( P1-P2 to P2-P1)
|
|
30
35
|
# returns the flipped score in string
|
|
31
|
-
def
|
|
32
|
-
flipped_score =
|
|
36
|
+
def flipped
|
|
37
|
+
flipped_score = []
|
|
33
38
|
(0...@scores.length).step(2).each do |i|
|
|
34
|
-
flipped_score
|
|
35
|
-
flipped_score = flipped_score + ',' if !(i == @scores.length-2)
|
|
39
|
+
flipped_score << [@scores[i+1], @scores[i]].join('-')
|
|
36
40
|
end
|
|
37
|
-
|
|
41
|
+
flipped_score.join(', ')
|
|
38
42
|
end
|
|
39
43
|
|
|
40
44
|
# returns who won the match
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tennis
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rohan Katyal
|
|
@@ -66,6 +66,7 @@ files:
|
|
|
66
66
|
- ".travis.yml"
|
|
67
67
|
- Gemfile
|
|
68
68
|
- LICENSE
|
|
69
|
+
- Makefile
|
|
69
70
|
- README.md
|
|
70
71
|
- Rakefile
|
|
71
72
|
- lib/tennis.rb
|