lib/bridge/score.rb in bridge-0.0.25 vs lib/bridge/score.rb in bridge-0.0.26

- old
+ new

@@ -25,10 +25,21 @@ # Returns nr of overtricks or undertricks. 0 if contract was made without them def result tricks - tricks_to_make_contract end + # Returns string with nr of tricks relative to contract level + def result_string + if result > 0 + "+" << result.to_s + elsif result == 0 + "=" + else + result.to_s + end + end + # Returns true if contract was made, false otherwise def made? result >= 0 end @@ -185,17 +196,10 @@ end (contracts + contracts.map { |c| c + "X" } + contracts.map { |c| c + "XX" } ).each do |contract| [true, false].each do |vulnerable| (0..13).each do |tricks| score = new(:contract => contract.sub("H/S", "S").sub("C/D", "C"), :tricks => tricks, :vulnerable => vulnerable) - if score.result > 0 - taken = "+" << score.result.to_s - elsif score.result == 0 - taken = "=" - else - taken = score.result.to_s - end - result[contract + taken + (score.vulnerable? ? "v" : "")] = score.points + result[contract + score.result_string + (score.vulnerable? ? "v" : "")] = score.points end end end result end