bridge 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -23,6 +23,7 @@ Arguments:
23
23
  Methods:
24
24
  * Score#made? -- Boolean
25
25
  * Score#result -- Integer, relative to contract level i.e. -1 (one down), 1 (overtrick), 0 (contract made)
26
+ * Score#result_string -- String, relative to contract level i.e "+1", "=", "-3"
26
27
  * Score#points -- Integer, calculated full value
27
28
 
28
29
  You can also ask for all possible contracts finished with given points:
data/lib/bridge/score.rb CHANGED
@@ -27,6 +27,17 @@ module Bridge
27
27
  tricks - tricks_to_make_contract
28
28
  end
29
29
 
30
+ # Returns string with nr of tricks relative to contract level
31
+ def result_string
32
+ if result > 0
33
+ "+" << result.to_s
34
+ elsif result == 0
35
+ "="
36
+ else
37
+ result.to_s
38
+ end
39
+ end
40
+
30
41
  # Returns true if contract was made, false otherwise
31
42
  def made?
32
43
  result >= 0
@@ -187,14 +198,7 @@ module Bridge
187
198
  [true, false].each do |vulnerable|
188
199
  (0..13).each do |tricks|
189
200
  score = new(:contract => contract.sub("H/S", "S").sub("C/D", "C"), :tricks => tricks, :vulnerable => vulnerable)
190
- if score.result > 0
191
- taken = "+" << score.result.to_s
192
- elsif score.result == 0
193
- taken = "="
194
- else
195
- taken = score.result.to_s
196
- end
197
- result[contract + taken + (score.vulnerable? ? "v" : "")] = score.points
201
+ result[contract + score.result_string + (score.vulnerable? ? "v" : "")] = score.points
198
202
  end
199
203
  end
200
204
  end
@@ -1,3 +1,3 @@
1
1
  module Bridge
2
- VERSION = "0.0.25"
2
+ VERSION = "0.0.26"
3
3
  end
data/test/test_score.rb CHANGED
@@ -54,6 +54,14 @@ class TestScore < Test::Unit::TestCase
54
54
  assert_equal -2, score.result
55
55
  end
56
56
 
57
+ test "return result string" do
58
+ assert_equal "+2", @score.result_string
59
+ score = Bridge::Score.new(:contract => "6S", :tricks => 12)
60
+ assert_equal "=", score.result_string
61
+ score = Bridge::Score.new(:contract => "6S", :tricks => 10)
62
+ assert_equal "-2", score.result_string
63
+ end
64
+
57
65
  test "return vulnerable" do
58
66
  assert_false @score.vulnerable?
59
67
  score = Bridge::Score.new(:contract => "6S", :vulnerable => true, :tricks => 12)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 25
9
- version: 0.0.25
8
+ - 26
9
+ version: 0.0.26
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jakub Ku\xC5\xBAma"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-21 00:00:00 +02:00
18
+ date: 2010-08-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -79,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- hash: -289614348859351753
82
+ hash: -1652863702179833470
83
83
  segments:
84
84
  - 0
85
85
  version: "0"