card_deck 4.0.0.pre.333 → 4.0.0.pre.337
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/card_deck/card.rb +51 -0
- data/lib/card_deck/deck.rb +24 -0
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTg3MGU4NGMzNWEyYzNmZTVkMjQ2YjFlYmYzYTczYTkxNTM1OTlkMQ==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 282ea40545f46312459eab9f84e7b6567b61b5b6deaf6cf0aaa58da256d4ac6b
|
4
|
+
data.tar.gz: 604d69e1b236360b7cf37eb7520208c1004d8b57dc05261628f32edc3f8829f3
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZmI0NmI4MzUxZGNjM2JkNmRjZTRmZjJiNTZhMmIxMjhhY2ZlODFkYmQyYjg4
|
11
|
-
ZWEwMDg1MTE2NzQ4ZDJkMjlkNTdlMWQ2NGE5NjgyNzhiMWU5NjY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NzFhNWNkZmZhM2UzODZjMGIwOGQ0ZTMxZjFiNjQzNmVhMThlYTUyN2MzMThk
|
14
|
-
MmQ5NjZiOWQxM2Q3Mzc2ZmZkMWVhNzI3Y2I3ZjgwMmY2NmQ5ZjQ1NzM1OTk0
|
15
|
-
OWVkZGFlNWZkYmVhNGI2ZmYzNjRhZjY4NTBiOGJmYzRkMTI4ZDU=
|
6
|
+
metadata.gz: a41a1903e8bc50bca20d9c1ec4312ee3ebf9158a1e4533c66c3ce2b5e23f5a375b4f3b6161fd4988a210616fde42c695fc920e85c56e550ea75789d7b20a4424
|
7
|
+
data.tar.gz: 6c3df06f0e9a10aee5912875cc48b7dd1134e12344a0534c75e3a9749aa368244601fe222f23de7a91c3aa34994440b37417d12873638934d19be3b54a0f5d3d
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module CardDeck # The gem
|
2
|
+
|
3
|
+
class CardError < StandardError; end # Errors for when you incorrectly use a card.
|
4
|
+
class Card # The central part of any card game. It is what makes card games 'Card' games.
|
5
|
+
Hearts, Spades, Diamonds, Clubs = "\u2665", "\u2660", "\u2666", "\u2663" # Suits
|
6
|
+
Num = %w(Ace King Queen Jack Joker) + Array(2..10) # Legal arguments for parameter num in Card#new.
|
7
|
+
Suit = [Hearts, Spades, Diamonds, Clubs] # Legal arguments for parameter suit in Card#new
|
8
|
+
attr_accessor :num # @return [String, Fixnum] must be Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, or Joker
|
9
|
+
attr_accessor :suit # @return [String] must be spades, diamonds, clubs, or hearts
|
10
|
+
|
11
|
+
=begin
|
12
|
+
@param suit [String]
|
13
|
+
@param num [String, Fixnum]
|
14
|
+
=end
|
15
|
+
def initialize(num=Num.sample, suit=Suit.sample)
|
16
|
+
suit = Card.const_get suit.capitalize unless Suit.include? suit
|
17
|
+
@num, @suit = num, suit
|
18
|
+
end
|
19
|
+
|
20
|
+
=begin
|
21
|
+
The shorter representation of the card
|
22
|
+
@return [String]
|
23
|
+
=end
|
24
|
+
def abbreviation
|
25
|
+
unless @num == "Joker"
|
26
|
+
if @num == 10 then @suit + @num.to_s
|
27
|
+
else @suit + Array(@num.to_s).fetch(0) end
|
28
|
+
else @num.to_s end
|
29
|
+
end
|
30
|
+
def black? # @return [Boolean]
|
31
|
+
suit == Spades || suit == Clubs
|
32
|
+
end
|
33
|
+
def red? # @return [Boolean]
|
34
|
+
suit == Hearts || suit == Diamonds
|
35
|
+
end
|
36
|
+
alias abbr abbreviation
|
37
|
+
alias to_s abbr
|
38
|
+
alias inspect abbreviation
|
39
|
+
end
|
40
|
+
module_function
|
41
|
+
=begin
|
42
|
+
@return [Card]
|
43
|
+
@param [String, Fixnum] num
|
44
|
+
@param [String] suit
|
45
|
+
@see Card#initialize
|
46
|
+
An easier way to generate a card
|
47
|
+
=end
|
48
|
+
def Card(num=Card::Num.sample, suit=Card::Suit.sample)
|
49
|
+
Card.new num, suit
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "card_deck/card"
|
2
|
+
module CardDeck
|
3
|
+
def Deck(args=Hash.new(false))
|
4
|
+
Deck.new args
|
5
|
+
end
|
6
|
+
class Deck # The deck
|
7
|
+
attr_accessor :cards # @return [Array<Card>]
|
8
|
+
def initialize(args=Hash.new(false)) # Creates a new Deck. Includes Jokers when parmeter args == {jokers: true}
|
9
|
+
@cards = Array.new
|
10
|
+
Card::Suit.each do |suit|
|
11
|
+
stock 'Ace', suit
|
12
|
+
(2..10).each {|num| stock num, suit}
|
13
|
+
stock 'Jack', suit
|
14
|
+
stock 'Queen', suit
|
15
|
+
stock 'King', suit
|
16
|
+
end
|
17
|
+
2.times {stock 'Joker'} if args[:jokers]
|
18
|
+
end
|
19
|
+
private
|
20
|
+
def stock(num, suit=Card::Suit.sample) # Creates a Card to add to Deck#cards
|
21
|
+
@cards.push Card.new num, suit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card_deck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.pre.
|
4
|
+
version: 4.0.0.pre.337
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Perlmutter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec-its
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Supplies the core parts of any card game. To use the deck, call shuffle
|
@@ -50,6 +50,8 @@ files:
|
|
50
50
|
- LICENSE.md
|
51
51
|
- README.md
|
52
52
|
- lib/card_deck.rb
|
53
|
+
- lib/card_deck/card.rb
|
54
|
+
- lib/card_deck/deck.rb
|
53
55
|
homepage: https://github.com/zrp200/card_deck
|
54
56
|
licenses:
|
55
57
|
- MIT
|
@@ -60,17 +62,17 @@ require_paths:
|
|
60
62
|
- lib
|
61
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
64
|
requirements:
|
63
|
-
- -
|
65
|
+
- - ">="
|
64
66
|
- !ruby/object:Gem::Version
|
65
67
|
version: '0'
|
66
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
69
|
requirements:
|
68
|
-
- -
|
70
|
+
- - ">"
|
69
71
|
- !ruby/object:Gem::Version
|
70
72
|
version: 1.3.1
|
71
73
|
requirements: []
|
72
74
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.4
|
75
|
+
rubygems_version: 2.7.4
|
74
76
|
signing_key:
|
75
77
|
specification_version: 4
|
76
78
|
summary: The central part of a card game
|