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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +9 -0
  3. data/lib/tennis/version.rb +1 -1
  4. data/lib/tennis.rb +14 -10
  5. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea95bc7f40b6be2a97429ab809d5ed3f94ea995c
4
- data.tar.gz: 80ba1df7f16b3a264e03ca3bc6f8f700982b434b
3
+ metadata.gz: f6e209d9196cecd2a9e47953f230d89d63496aae
4
+ data.tar.gz: d5bd1a1d77ecc2d243207bb6cd8315a53fd1d54a
5
5
  SHA512:
6
- metadata.gz: 94c17c9714bd48a45974e8d4fd641a0f80083aa6fd64eddd540bf1c3116dd8767d3103738260e81ad39a04b6d7290f163531cff6eac8db32444d8f7d98c90fb6
7
- data.tar.gz: 96eda3aad474683c9c493637eee575aae279d247a57b9baaf7f4113e4e340f9d0a6d8ed81859b4f4c94127c15a71d5967eacd23c681ccf34ca8c3ae538425987
6
+ metadata.gz: 754ce0601818ee8e17e4222b8fb31884a1b6f00fb2d2c5500e967fe16ae0f6c583d4c5c71d731e524be9e2a49af97905c0f1b18cac6ef2249eca35b69263d0bb
7
+ data.tar.gz: 1f3c1371982bdcccf50d37ba8f8967182e02e94c4995eac80f20ec3d1efd9f1d324dfc489beebb559ce608ea628f1cb35ac9ccc6100081f142a04f9c3c7dcef3
data/Makefile ADDED
@@ -0,0 +1,9 @@
1
+
2
+ all:
3
+ rake spec
4
+
5
+ build:
6
+ gem build tennis.gemspec
7
+
8
+ # to push to rubygems
9
+ # gem push tennis-0.1.1.gem
@@ -1,3 +1,3 @@
1
1
  class Tennis
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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
- # getter method for the original score string
25
- def get_result
26
- return self.result.to_s
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 flip
32
- flipped_score = ''
36
+ def flipped
37
+ flipped_score = []
33
38
  (0...@scores.length).step(2).each do |i|
34
- flipped_score = flipped_score + @scores[i+1].to_s + '-' + @scores[i].to_s
35
- flipped_score = flipped_score + ',' if !(i == @scores.length-2)
39
+ flipped_score << [@scores[i+1], @scores[i]].join('-')
36
40
  end
37
- return flipped_score
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.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