deck-of-cards 0.0.1 → 0.0.2
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.
- data/Gemfile.lock +14 -0
- data/deck-of-cards.gemspec +7 -6
- data/lib/deck-of-cards.rb +13 -7
- data/lib/deck-of-cards/card.rb +23 -4
- data/lib/deck-of-cards/version.rb +1 -1
- data/test/test_deck.rb +7 -2
- metadata +3 -3
- data/lib/deck-of-cards/compare_cards.rb +0 -22
data/Gemfile.lock
ADDED
data/deck-of-cards.gemspec
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path
|
3
|
-
require
|
2
|
+
$:.push File.expand_path '../lib/deck-of-cards', __FILE__
|
3
|
+
require 'card'
|
4
|
+
require 'version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
7
|
+
s.name = 'deck-of-cards'
|
7
8
|
s.version = DeckOfCards::VERSION
|
8
|
-
s.authors = [
|
9
|
-
s.email = [
|
10
|
-
s.homepage =
|
9
|
+
s.authors = ['shannon skipper']
|
10
|
+
s.email = ['shannonskipper@gmail.com']
|
11
|
+
s.homepage = 'https://github.com/Havenwood/deck-of-cards'
|
11
12
|
s.summary = %q{a minimalist 'deck of cards' gem}
|
12
13
|
s.description = %q{A minimalist 'deck of cards' Ruby gem.}
|
13
14
|
|
data/lib/deck-of-cards.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
$:.unshift File.expand_path '../../lib/deck-of-cards', __FILE__
|
2
|
+
|
3
|
+
require 'card'
|
4
|
+
require 'version'
|
4
5
|
|
5
6
|
class DeckOfCards
|
6
7
|
attr_reader :cards
|
7
8
|
|
9
|
+
SUITS = %w[Hearts Spades Diamonds Clubs]
|
10
|
+
RANKS = [*2..10, 'Jack', 'Queen', 'King', 'Ace']
|
11
|
+
|
8
12
|
def initialize
|
9
13
|
@cards = []
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
SUITS.product(RANKS) { |suit, rank| @cards << Card.new(rank, suit) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"#{@cards.count}-card deck."
|
13
19
|
end
|
14
20
|
|
15
21
|
def shuffle
|
@@ -17,7 +23,7 @@ class DeckOfCards
|
|
17
23
|
end
|
18
24
|
|
19
25
|
def cut
|
20
|
-
@cards.rotate! @cards.count
|
26
|
+
@cards.rotate! @cards.count / 2
|
21
27
|
end
|
22
28
|
|
23
29
|
alias split cut
|
data/lib/deck-of-cards/card.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
class Card
|
2
|
-
include CompareCards
|
3
|
-
|
1
|
+
class Card
|
4
2
|
attr_reader :rank, :suit
|
5
3
|
|
6
4
|
def initialize rank, suit
|
@@ -14,4 +12,25 @@ class Card
|
|
14
12
|
def to_s
|
15
13
|
"#{@rank} of #{@suit}"
|
16
14
|
end
|
17
|
-
|
15
|
+
|
16
|
+
include Comparable
|
17
|
+
|
18
|
+
def <=> other_card
|
19
|
+
self.value <=> other_card.value
|
20
|
+
end
|
21
|
+
|
22
|
+
def value
|
23
|
+
case @rank
|
24
|
+
when 'Ace'
|
25
|
+
14
|
26
|
+
when 'King'
|
27
|
+
13
|
28
|
+
when 'Queen'
|
29
|
+
12
|
30
|
+
when 'Jack'
|
31
|
+
11
|
32
|
+
else
|
33
|
+
@rank
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/test/test_deck.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.expand_path '../../lib/deck-of-cards', __FILE__
|
2
3
|
|
3
4
|
require 'minitest/autorun'
|
4
5
|
require 'minitest/pride'
|
5
6
|
require 'set'
|
6
|
-
|
7
|
+
require File.expand_path '../../lib/deck-of-cards.rb', __FILE__
|
7
8
|
|
8
9
|
describe DeckOfCards do
|
9
10
|
before do
|
@@ -11,7 +12,11 @@ describe DeckOfCards do
|
|
11
12
|
@correct_cards = []
|
12
13
|
suits = ["Hearts", "Spades", "Diamonds", "Clubs"]
|
13
14
|
ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King", "Ace"]
|
14
|
-
suits.each
|
15
|
+
suits.each do |suit|
|
16
|
+
ranks.each do |rank|
|
17
|
+
@correct_cards << Card.new(rank, suit)
|
18
|
+
end
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
describe "when a deck is created" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deck-of-cards
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A minimalist 'deck of cards' Ruby gem.
|
15
15
|
email:
|
@@ -19,12 +19,12 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- Gemfile
|
22
|
+
- Gemfile.lock
|
22
23
|
- README.md
|
23
24
|
- Rakefile
|
24
25
|
- deck-of-cards.gemspec
|
25
26
|
- lib/deck-of-cards.rb
|
26
27
|
- lib/deck-of-cards/card.rb
|
27
|
-
- lib/deck-of-cards/compare_cards.rb
|
28
28
|
- lib/deck-of-cards/version.rb
|
29
29
|
- test/test_deck.rb
|
30
30
|
homepage: https://github.com/Havenwood/deck-of-cards
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module CompareCards
|
2
|
-
include Comparable
|
3
|
-
|
4
|
-
def value
|
5
|
-
case @rank
|
6
|
-
when 'Ace'
|
7
|
-
14
|
8
|
-
when 'King'
|
9
|
-
13
|
10
|
-
when 'Queen'
|
11
|
-
12
|
12
|
-
when 'Jack'
|
13
|
-
11
|
14
|
-
else
|
15
|
-
@rank.to_i
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def <=> other_card
|
20
|
-
self.value <=> other_card.value
|
21
|
-
end
|
22
|
-
end
|