badcards 0.2.1 → 0.2.3
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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/badcards/card.rb +22 -6
- data/lib/badcards/deck.rb +11 -0
- data/lib/badcards/version.rb +1 -1
- data/spec/badcards/card_spec.rb +24 -0
- data/spec/badcards/deck_spec.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e65c8a32d66371c3b2b62a05d6305df0ea9446c9
|
4
|
+
data.tar.gz: c8dd7c3580ed698e6ab35b62255813e776596764
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8fd2516fb581527bafcf2c06db13472f23e0076643863eee66becc532b5f02eb6c25d9df7b33ae771ce7dc6ab30607df81ec7c00835159354e89d43a84c1a66
|
7
|
+
data.tar.gz: 7757e906f56989b83827adcc9127ffdf8913f21cf8c409fb8a03eaebbdb290c06e398e009553257d427cc29b7e66804b7389375547e9f2ce7194ddd5bf298bb6
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# BaDcards
|
2
|
+
[](http://badge.fury.io/rb/badcards)
|
2
3
|
[](https://travis-ci.org/BensPotatoes/BaDCards)
|
3
4
|
[](https://coveralls.io/r/BensPotatoes/BaDCards?branch=master)
|
4
5
|
|
data/lib/badcards/card.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
class Card
|
2
2
|
SUITS = %w[Diamonds Clubs Hearts Spades]
|
3
|
+
SHORT_SUITS = {
|
4
|
+
'D' => 'Diamonds',
|
5
|
+
'C' => 'Clubs',
|
6
|
+
'H' => 'Hearts',
|
7
|
+
'S' => 'Spades'
|
8
|
+
}
|
9
|
+
|
3
10
|
VALUES = %w[Ace 2 3 4 5 6 7 8 9 10 Jack Queen King]
|
11
|
+
SHORT_VALUES = {
|
12
|
+
'A' => 'Ace',
|
13
|
+
'J' => 'Jack',
|
14
|
+
'Q' => 'Queen',
|
15
|
+
'K' => 'Jack'
|
16
|
+
}
|
4
17
|
|
5
18
|
S3_URLS = {
|
6
19
|
"ace+diamonds" => "https://s3-us-west-2.amazonaws.com/badcards/cards/diamond/ace.png",
|
@@ -61,15 +74,14 @@ class Card
|
|
61
74
|
}
|
62
75
|
|
63
76
|
def initialize(value, suit)
|
64
|
-
if !VALUES.include?(value)
|
77
|
+
if !VALUES.include?(value) && !VALUES.include?(SHORT_VALUES[value])
|
65
78
|
raise ArgumentError, "Invalid Card value"
|
66
79
|
end
|
67
|
-
if !SUITS.include?(suit)
|
80
|
+
if !SUITS.include?(suit) && !SUITS.include?(SHORT_SUITS[suit])
|
68
81
|
raise ArgumentError, "Invalid Card suit"
|
69
82
|
end
|
70
|
-
@value = value
|
71
|
-
@suit = suit
|
72
|
-
@image = S3_URLS["#{value.downcase}+#{suit.downcase}"]
|
83
|
+
@value = SHORT_VALUES[value] || value
|
84
|
+
@suit = SHORT_SUITS[suit] || suit
|
73
85
|
end
|
74
86
|
|
75
87
|
def value
|
@@ -81,7 +93,11 @@ class Card
|
|
81
93
|
end
|
82
94
|
|
83
95
|
def img
|
84
|
-
|
96
|
+
S3_URLS["#{value.downcase}+#{suit.downcase}"]
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_s
|
100
|
+
"#{value} of #{suit}"
|
85
101
|
end
|
86
102
|
|
87
103
|
def self.all_cards
|
data/lib/badcards/deck.rb
CHANGED
@@ -20,6 +20,17 @@ class Deck
|
|
20
20
|
@cards.first
|
21
21
|
end
|
22
22
|
|
23
|
+
def shuffle(num_times = 12)
|
24
|
+
num_times.times do
|
25
|
+
@cards.each_with_index do |card, index|
|
26
|
+
switch = rand(size)
|
27
|
+
@cards[index] = @cards[switch]
|
28
|
+
@cards[switch] = card
|
29
|
+
end
|
30
|
+
end
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
23
34
|
def draw(num_to_draw = 1, hand_for_draw = nil)
|
24
35
|
@drawn = []
|
25
36
|
num_to_draw.times do
|
data/lib/badcards/version.rb
CHANGED
data/spec/badcards/card_spec.rb
CHANGED
@@ -12,6 +12,16 @@ describe Card do
|
|
12
12
|
make_card(value, suit)
|
13
13
|
@card.value.should == value
|
14
14
|
end
|
15
|
+
|
16
|
+
it 'should have an image' do
|
17
|
+
make_card(value, suit)
|
18
|
+
@card.img.should == Card::S3_URLS["#{value.downcase}+#{suit.downcase}"]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should print neatly' do
|
22
|
+
make_card(value, suit)
|
23
|
+
@card.to_s.should == "#{value} of #{suit}"
|
24
|
+
end
|
15
25
|
end
|
16
26
|
|
17
27
|
it 'should fail for an invalid suit' do
|
@@ -21,5 +31,19 @@ describe Card do
|
|
21
31
|
it 'should fail for an invalid value' do
|
22
32
|
expect { make_card('fake_value', 'Spades') }.to raise_error
|
23
33
|
end
|
34
|
+
|
35
|
+
Card::SHORT_VALUES.each do |short, long|
|
36
|
+
it "should not fail for short value: #{short}" do
|
37
|
+
make_card(short, 'Spades')
|
38
|
+
@card.value.should == long
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Card::SHORT_SUITS.each do |short, long|
|
43
|
+
it "should not fail for short suit: #{short}" do
|
44
|
+
make_card('Ace', short)
|
45
|
+
@card.suit.should == long
|
46
|
+
end
|
47
|
+
end
|
24
48
|
end
|
25
49
|
end
|
data/spec/badcards/deck_spec.rb
CHANGED
@@ -23,10 +23,10 @@ describe Deck do
|
|
23
23
|
if @match
|
24
24
|
found_cards << true
|
25
25
|
next
|
26
|
-
else
|
27
|
-
found_cards << false
|
28
26
|
end
|
29
27
|
end
|
28
|
+
found_cards.all?.should == true
|
29
|
+
found_cards.count.should == 52
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -41,7 +41,10 @@ describe Deck do
|
|
41
41
|
|
42
42
|
describe 'operation' do
|
43
43
|
describe 'shuffling' do
|
44
|
-
|
44
|
+
it 'should not fail' do
|
45
|
+
@deck = Deck.new
|
46
|
+
@deck.shuffle
|
47
|
+
end
|
45
48
|
end
|
46
49
|
|
47
50
|
describe 'drawing' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: badcards
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Hsieh, Ben's Potatoes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|