tennis 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: f75cc2750ec34ca68ed936d8f66aac0da45e1b10
4
- data.tar.gz: 4d3cb1e0fcbc5fc0b98a4a733345891fa003f15f
3
+ metadata.gz: b058e15112d8268ef3ae828804e72656cb26dff3
4
+ data.tar.gz: 10aabb8eaacd31a048224e0fac0066a24db2f690
5
5
  SHA512:
6
- metadata.gz: 5330df6992790cd772a33510a090892c59a8593a496356a80844a2318d5181b4e95701a9ca70ad540e53ce2283386ceddcf8c9de2b35128337a4f30c7de0721b
7
- data.tar.gz: 92aeab0c4938a7c19512696a1ddef67821d824d94752a603a1915da5537f89b63f6e393129544d7a9d6d72f89f6518ae9010e70afc92af3e8883ec62da6b8b7d
6
+ metadata.gz: 422cbc0250672d9c11fd09dc75f0a54eef705b185b0a07c2e2c2331860002f438437f712cfbdcebc03e680425dddec5acfc2ef442953b9ee3e683a2d45b579fe
7
+ data.tar.gz: 81f5eb54ccb0eb62774fc9a513c749f98abe7735932e371ce7c8f234c030330aa37f688358d6b00b2b0c6879079e1bd7d1d1ba3706cb446b960bb571d9817ce8
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in tennis.gemspec
4
4
  gemspec
5
+
6
+ gem 'rspec'
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Tennis
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/tennis.svg)](http://badge.fury.io/rb/tennis) [![Build Status](https://travis-ci.org/racketlogger/tennis.svg)](https://travis-ci.org/racketlogger/tennis)
4
+
3
5
  Ruby gem with utilities to manage, print and validate tennis scores
4
6
 
7
+
5
8
  ## Installation
6
9
 
7
10
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ task :default => :spec
data/lib/tennis.rb CHANGED
@@ -2,102 +2,102 @@ require "tennis/version"
2
2
 
3
3
  module Tennis
4
4
  class << self
5
- def initialize(scores)
6
- @scores = scores != 'default-1' && scores != 'default-2' ? scores.split(/[-,,]/).map(&:to_i) : scores
7
- @result = (1 if scores == 'default-1') || (2 if scores == 'default-2') || :default
8
- if @result == :default
9
- # to check if score for only 1 set has been input
10
- validation_1 = @scores.length == 2
11
- # to check if any input > 7
12
- validation_2 = @scores.any? { |score| score > 7 }
13
- @result = :error if validation_1 || validation_2
14
- end
15
- end
5
+ def initialize(scores)
6
+ @scores = scores != 'default-1' && scores != 'default-2' ? scores.split(/[-,,]/).map(&:to_i) : scores
7
+ @result = (1 if scores == 'default-1') || (2 if scores == 'default-2') || :default
8
+ if @result == :default
9
+ # to check if score for only 1 set has been input
10
+ validation_1 = @scores.length == 2
11
+ # to check if any input > 7
12
+ validation_2 = @scores.any? { |score| score > 7 }
13
+ @result = :error if validation_1 || validation_2
14
+ end
15
+ end
16
16
 
17
- # returns who won the match
18
- # :incomplete_match (bad input/incomplete match)
19
- # :error (bad input for sure)
20
- # 1 (player-1 won)
21
- # 2 (player-2 won)
22
- def result
23
- return @result if @result != :default
24
- return @result = (@scores.length == 4) ? two_sets : three_sets
25
- end
17
+ # returns who won the match
18
+ # :incomplete_match (bad input/incomplete match)
19
+ # :error (bad input for sure)
20
+ # 1 (player-1 won)
21
+ # 2 (player-2 won)
22
+ def result
23
+ return @result if @result != :default
24
+ return @result = (@scores.length == 4) ? two_sets : three_sets
25
+ end
26
26
 
27
- # returns an array of points
28
- # returns (points_player_1 , points_player_2)
29
- # returns (0,0) for bad input
30
- def points
31
- @result = self.result
32
- (return [0, 0]) if @result == :error
33
- return (complete_match_points if @result == 1 || @result == 2) || incomplete_match_points
34
- end
27
+ # returns an array of points
28
+ # returns (points_player_1 , points_player_2)
29
+ # returns (0,0) for bad input
30
+ def points
31
+ @result = self.result
32
+ (return [0, 0]) if @result == :error
33
+ return (complete_match_points if @result == 1 || @result == 2) || incomplete_match_points
34
+ end
35
35
 
36
- private
36
+ private
37
37
 
38
- # helper method: called by RESULT method for valid matches with 2 sets
39
- def two_sets
40
- set_results = []
41
- [0, 2].each do |i|
42
- # tie breaker (assuming a 7 point tie breaker) or a 7-5 scores
43
- if @scores[i] == 7 || @scores[i+1] == 7
44
- set_results << (@scores[i] == 7 ? 1 : 2)
45
- # regular set victory - 6 games with a margin of 2
46
- else
47
- return :incomplete_match if ( @scores[i] - @scores[i + 1] ).abs < 2
48
- set_results << (@scores[i] == 6 ? 1 : 2)
49
- end
50
- end
51
- # incomplete match e.g: 6-4,5-3
52
- return (set_results[0] if set_results[0] == set_results[1]) || :incomplete_match
53
- end
38
+ # helper method: called by RESULT method for valid matches with 2 sets
39
+ def two_sets
40
+ set_results = []
41
+ [0, 2].each do |i|
42
+ # tie breaker (assuming a 7 point tie breaker) or a 7-5 scores
43
+ if @scores[i] == 7 || @scores[i+1] == 7
44
+ set_results << (@scores[i] == 7 ? 1 : 2)
45
+ # regular set victory - 6 games with a margin of 2
46
+ else
47
+ return :incomplete_match if ( @scores[i] - @scores[i + 1] ).abs < 2
48
+ set_results << (@scores[i] == 6 ? 1 : 2)
49
+ end
50
+ end
51
+ # incomplete match e.g: 6-4,5-3
52
+ return (set_results[0] if set_results[0] == set_results[1]) || :incomplete_match
53
+ end
54
54
 
55
- # helper method: called by RESULT method for valid matches with 3 sets
56
- def three_sets
57
- set_results = []
58
- [0, 2, 4].each do |i|
59
- # tie breaker (assuming a 7 point tie breaker) or a 7-5 score
60
- if @scores[i] == 7 || @scores[i + 1] == 7
61
- set_results << (@scores[i] == 7 ? 1 : 2)
62
- # regular set victory - 6 games with a margin of 2
63
- else
64
- return :incomplete_match if (@scores[i] - @scores[i + 1]).abs < 2
65
- set_results << (@scores[i] == 6 ? 1 : 2)
66
- end
67
- end
68
- # checks if the result has been decided in the first 2 sets
69
- # but the 3rd set is also present in the input
70
- return :error if set_results[0] == set_results[1]
71
- return set_results.count(1) ? 1 : 2
72
- end
55
+ # helper method: called by RESULT method for valid matches with 3 sets
56
+ def three_sets
57
+ set_results = []
58
+ [0, 2, 4].each do |i|
59
+ # tie breaker (assuming a 7 point tie breaker) or a 7-5 score
60
+ if @scores[i] == 7 || @scores[i + 1] == 7
61
+ set_results << (@scores[i] == 7 ? 1 : 2)
62
+ # regular set victory - 6 games with a margin of 2
63
+ else
64
+ return :incomplete_match if (@scores[i] - @scores[i + 1]).abs < 2
65
+ set_results << (@scores[i] == 6 ? 1 : 2)
66
+ end
67
+ end
68
+ # checks if the result has been decided in the first 2 sets
69
+ # but the 3rd set is also present in the input
70
+ return :error if set_results[0] == set_results[1]
71
+ return set_results.count(1) ? 1 : 2
72
+ end
73
73
 
74
- # helper method: called by POINTS for complete matches
75
- def complete_match_points
76
- points = [0, 0]
77
- @result = self.result
78
- points[@result - 1] = (@scores.length == 6) ? 12 : 14
79
- runner_up = (@result == 1) ? 2 : 1
80
- runner_up_points = player_points(runner_up)
81
- points[runner_up - 1] = runner_up_points < 8 ? runner_up_points : 8
82
- return points
83
- end
74
+ # helper method: called by POINTS for complete matches
75
+ def complete_match_points
76
+ points = [0, 0]
77
+ @result = self.result
78
+ points[@result - 1] = (@scores.length == 6) ? 12 : 14
79
+ runner_up = (@result == 1) ? 2 : 1
80
+ runner_up_points = player_points(runner_up)
81
+ points[runner_up - 1] = runner_up_points < 8 ? runner_up_points : 8
82
+ return points
83
+ end
84
84
 
85
- # helper method: called by POINTS for incomplete matches
86
- def incomplete_match_points
87
- points = [0, 0]
88
- player_1_points = player_points(1)
89
- player_2_points = player_points(2)
90
- points[0] = player_1_points < 10 ? player_1_points : 10
91
- points[1] = player_2_points < 10 ? player_2_points : 10
92
- return points
93
- end
85
+ # helper method: called by POINTS for incomplete matches
86
+ def incomplete_match_points
87
+ points = [0, 0]
88
+ player_1_points = player_points(1)
89
+ player_2_points = player_points(2)
90
+ points[0] = player_1_points < 10 ? player_1_points : 10
91
+ points[1] = player_2_points < 10 ? player_2_points : 10
92
+ return points
93
+ end
94
94
 
95
- # helper method: returns the POINTS of a player given the player number
96
- def player_points(player)
97
- player_scores = []
98
- @scores.each_with_index { |score, index| (player_scores << score; player +=2) if index == (player - 1) }
99
- player_scores = player_scores.sort! { |x, y| y <=> x }
100
- return player_scores[0] + player_scores[1]
101
- end
95
+ # helper method: returns the POINTS of a player given the player number
96
+ def player_points(player)
97
+ player_scores = []
98
+ @scores.each_with_index { |score, index| (player_scores << score; player +=2) if index == (player - 1) }
99
+ player_scores = player_scores.sort! { |x, y| y <=> x }
100
+ return player_scores[0] + player_scores[1]
101
+ end
102
102
  end
103
103
  end
@@ -1,3 +1,3 @@
1
1
  module Tennis
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
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.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Puchol
@@ -46,12 +46,14 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - ".rspec"
49
50
  - Gemfile
50
51
  - LICENSE
51
52
  - README.md
52
53
  - Rakefile
53
54
  - lib/tennis.rb
54
55
  - lib/tennis/version.rb
56
+ - spec/spec_helper.rb
55
57
  - tennis.gemspec
56
58
  homepage: ''
57
59
  licenses:
@@ -77,4 +79,5 @@ rubygems_version: 2.4.5
77
79
  signing_key:
78
80
  specification_version: 4
79
81
  summary: A gem to manage tennis scores.
80
- test_files: []
82
+ test_files:
83
+ - spec/spec_helper.rb