bridge 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bridge/deal.rb CHANGED
@@ -142,13 +142,22 @@ module Bridge
142
142
 
143
143
  def sort_by_color(trump = nil)
144
144
  DIRECTIONS.inject({}) do |sorted, direction|
145
- splitted_colors = split_colors(direction)
145
+ splitted_colors = cards_for(direction)
146
+ splitted_colors.reject! { |trump, cards| cards.empty? }
146
147
  sorted_colors = sort_colors(splitted_colors.keys, trump)
147
148
  sorted[direction] = sorted_colors.map { |color| splitted_colors.delete(color) }.flatten
148
149
  sorted
149
150
  end
150
151
  end
151
152
 
153
+ def cards_for(direction)
154
+ TRUMPS.inject({}) do |colors, trump|
155
+ cards = self[direction].select { |card| card.suit == trump }
156
+ colors[trump] = cards
157
+ colors
158
+ end
159
+ end
160
+
152
161
  private
153
162
 
154
163
  def must_be_direction!(string)
@@ -160,14 +169,6 @@ module Bridge
160
169
  instance_variable_set("@#{direction.to_s.downcase}", cards)
161
170
  end
162
171
 
163
- def split_colors(direction)
164
- TRUMPS.inject({}) do |colors, trump|
165
- cards = self[direction].select { |card| card.suit == trump }
166
- colors[trump] = cards unless cards.empty?
167
- colors
168
- end
169
- end
170
-
171
172
  def sort_colors(colors, trump = nil)
172
173
  black = ["S", "C"] & colors
173
174
  red = ["H", "D"] & colors
@@ -1,3 +1,3 @@
1
1
  module Bridge
2
- VERSION = "0.0.24"
2
+ VERSION = "0.0.25"
3
3
  end
data/test/test_deal.rb CHANGED
@@ -145,14 +145,15 @@ class TestDealSort < Test::Unit::TestCase
145
145
  "H" => @deal.n.select { |c| c.suit == "H" },
146
146
  "D" => @deal.n.select { |c| c.suit == "D" },
147
147
  "C" => @deal.n.select { |c| c.suit == "C" } }
148
- assert_equal expected, @deal.send(:split_colors, "N")
148
+ assert_equal expected, @deal.cards_for("N")
149
149
  end
150
150
 
151
151
  test "return colors as key only if cards are present on hand" do
152
152
  expected = { "S" => @deal.e.select { |c| c.suit == "S" },
153
+ "H" => [],
153
154
  "D" => @deal.e.select { |c| c.suit == "D" },
154
155
  "C" => @deal.e.select { |c| c.suit == "C" } }
155
- assert_equal expected, @deal.send(:split_colors, "E")
156
+ assert_equal expected, @deal.cards_for("E")
156
157
  end
157
158
 
158
159
  test "return sorted 4 colors" do
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridge
3
3
  version: !ruby/object:Gem::Version
4
- hash: 47
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 24
10
- version: 0.0.24
8
+ - 25
9
+ version: 0.0.25
11
10
  platform: ruby
12
11
  authors:
13
12
  - "Jakub Ku\xC5\xBAma"
@@ -16,16 +15,16 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-08-20 00:00:00 +02:00
18
+ date: 2010-08-21 00:00:00 +02:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
22
+ name: bundler
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: 15424063
29
28
  segments:
30
29
  - 1
31
30
  - 0
@@ -34,7 +33,6 @@ dependencies:
34
33
  - 5
35
34
  version: 1.0.0.rc.5
36
35
  type: :development
37
- name: bundler
38
36
  prerelease: false
39
37
  version_requirements: *id001
40
38
  description: Useful contract bridge utilities - deal generator, id to deal and deal to id conversion
@@ -81,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
79
  requirements:
82
80
  - - ">="
83
81
  - !ruby/object:Gem::Version
84
- hash: 3
82
+ hash: -289614348859351753
85
83
  segments:
86
84
  - 0
87
85
  version: "0"
@@ -90,7 +88,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
88
  requirements:
91
89
  - - ">="
92
90
  - !ruby/object:Gem::Version
93
- hash: 23
94
91
  segments:
95
92
  - 1
96
93
  - 3