card_deck 2.1.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/card.rb +12 -12
- data/lib/deck.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzU3ZDY0NzJjMjI5ZTdjNzlkODJmYjAyNjU2NjE0M2NhM2Q4MzBjMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjI2NWM4YjhkYWZhODU1ZjMxYzFjM2EzZTI3M2U2ZWY3ZDUwNDNjYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjQyMDQ0MzYyNGRmNjAzMmQ1YmY5MDBmOTAzMzcwMjI0MWRjYjMyNjU2N2I3
|
10
|
+
MDMwYTFkZjk4NTZjNDk2YjkzNTQ1ODI3YzFhYThkNzY0ZTBhNjEwY2E3Mzll
|
11
|
+
NDA0MDU1ODkxMTZjOGM1NDBmZTgxOThhOWU0MWQ2MGE3NWVhM2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2U1OGEwMGRhMTJiNTU1ODJiOTY5OWVjZjhmNjExMjNlN2E5ZjI0MmUyNzZh
|
14
|
+
ZjViZGIxMDNlMGFhZjJhNzBkODc2MzBiN2U2NGVjYTRkM2YwZTQ1ZWM1Yzdk
|
15
|
+
OGEyMmQ0MDFiOWNiNDE3YjkzOThkYWQ3YWZjYzNmMGYzMGM0ZmU=
|
data/lib/card.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
module CardDeck # The gem
|
2
|
-
def Card(num, suit); Card.new num, suit; end # an easier way to generate a card
|
2
|
+
def Card(num=Card::Num, suit=Card::Suit.sample); Card.new num, suit; end # an easier way to generate a card
|
3
3
|
class CardError < StandardError; end # Errors for when you incorrectly use a card.
|
4
4
|
class Card # The central part of any card game. It is what makes card games 'Card' games.
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
Hearts, Spades, Diamonds, Clubs = "\u2665", "\u2660", "\u2666", "\u2663" # Suits
|
6
|
+
Num = %w(Ace King Queen Jack Joker) + (2..10).to_a # Legal arguments for parameter num in Card#new.
|
7
|
+
Suit = [Hearts, Spades, Diamonds, Clubs] # Legal arguments for parameter suit in Card#new
|
8
8
|
attr_accessor :num # The card's number. Must be Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, or Joker
|
9
9
|
attr_accessor :suit # The card's suit. Must be Spades, Diamonds, Clubs, or Hearts.
|
10
|
-
def initialize(num, suit) # Creates a new card. Parameter num is the card's number. Parameter suit is the card's suit
|
11
|
-
unless
|
10
|
+
def initialize(num=Num.sample, suit=Suit.sample) # Creates a new card. Parameter num is the card's number. Parameter suit is the card's suit. When given no arguments, the num and suit are randomly generated
|
11
|
+
unless Suit.include? suit
|
12
12
|
suit = case suit.downcase
|
13
|
-
when "diamonds" then
|
14
|
-
when "spades" then
|
15
|
-
when "hearts" then
|
16
|
-
when "clubs" then
|
13
|
+
when "diamonds" then Diamonds
|
14
|
+
when "spades" then Spades
|
15
|
+
when "hearts" then Hearts
|
16
|
+
when "clubs" then Clubs
|
17
17
|
end
|
18
18
|
end
|
19
19
|
@num, @suit = num, suit
|
20
20
|
end
|
21
|
-
def self.gen; self.new NUM.sample, SUIT.sample; end # Creates a random new card.
|
22
21
|
def abbreviation # The shorter representation of the card
|
23
22
|
unless @num == "Joker"
|
24
23
|
if @num == 10 then "#{@suit}#{@num}"
|
@@ -29,7 +28,8 @@ module CardDeck # The gem
|
|
29
28
|
@num
|
30
29
|
end
|
31
30
|
end
|
32
|
-
def black?; suit ==
|
31
|
+
def black?; suit == Spades || suit == Clubs; end # Tests if the suit color is black
|
32
|
+
def red?; suit == Hearts || suit == Diamonds; end # Tests if the suit color is red
|
33
33
|
alias abbr abbreviation # A shorter method name
|
34
34
|
alias to_s abbr
|
35
35
|
end
|
data/lib/deck.rb
CHANGED
@@ -4,7 +4,7 @@ module CardDeck
|
|
4
4
|
attr_accessor :cards # The cards in the deck
|
5
5
|
def initialize(args=Hash.new(false)) # Creates a new Deck. Includes Jokers when parmeter args == {jokers: true}
|
6
6
|
@cards = Array.new
|
7
|
-
for suit in Card::
|
7
|
+
for suit in Card::Suit
|
8
8
|
stock 'Ace', suit
|
9
9
|
for num in (2..10).to_a; stock num, suit; end
|
10
10
|
stock 'Jack', suit
|
@@ -14,6 +14,6 @@ module CardDeck
|
|
14
14
|
2.times {stock 'Joker'} if args[:jokers]
|
15
15
|
end
|
16
16
|
private
|
17
|
-
def stock(num, suit=Card::
|
17
|
+
def stock(num, suit=Card::Suit.sample); @cards.push Card.new num, suit; end # Creates a Card to add to Deck#cards
|
18
18
|
end
|
19
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card_deck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Perlmutter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|