card_deck 4.0.0.332 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODlmOWRiNzkzZWQwNzdiMzc3OWZmNzI4MDk4NmNjZjUwNWUzZTdmNw==
4
+ MGEwMGZkYjU4OWZlZTZmOTExM2FkNTEzZGM3OGViYjQ2ZTJiZTE2Yg==
5
5
  data.tar.gz: !binary |-
6
- YzVjNzE2N2YzNDMxMGRlODVkZWE0OWMwYWJkYTIwMWQ5ZGZkNDVlNw==
6
+ NTRmZWNjZjAwZmVlMzBjMDRmMGE1OTU0MzEyMTRhMjU5NzAzNjA2NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDUwZDU2NjNlNDY5YWU2YzcyMDAxMTBmYmI4MjU2YmQ4NzVhOTVkODBkNjEz
10
- MWU5MzEzMjUwNDQxNGMwMThkNjZiOTFhMzNiZDViZjhmMDhkMjU1ZjIyOGI1
11
- MTJhOTY0MWNlMTI5NzVlYjhmNGRjZTFjOTFmNGE2ZjhiZjhkN2Y=
9
+ ZDdhM2Y2ZmRjNzllY2M5NmYwOTgzMmJkNWM2NzIwOTYzODk2NWFmYzE2Mzhm
10
+ MjNmZWU2YmU1YTkxMTA0ODllOTc4ZDJhMWE3MTE1NGJjZjNhMjE3YjVlNmM1
11
+ MzNjNzViZmZlMDg2ZGE3YzA5ZDUxZTBiMGYzOWMxZDhkOTU1NjE=
12
12
  data.tar.gz: !binary |-
13
- OWY3NmRmOTBmNTg0NGU3ZTgxY2Q1MzIxM2NhOTk0Y2RjOWFkN2Q0YjQzODg1
14
- Yjg0YmVhMWU5Yzk4YjZmN2Q0MmVjYmE1MTg4YTAwYTYzOWI4N2MyNzZjMjk5
15
- MjY1MzJhYTZkODIxNTVmNGFjNGExMTRkZWQzNGMxYWRhMzU5ZDY=
13
+ YjVmMzA1NDdjNDUwNDY3N2ExODQ2ZDE1NjIwYmFmZGFhMzYxMDQwZDdkM2Y4
14
+ NTJjY2Y1NmMyNDE1NjdlZDQ4ODk5ZjI4ZmNkN2QyNmM3ZjFhMWVkYjkwNzM3
15
+ NGYwZTUwZGYwMjRkY2I1MGI5OWFhYTQ4Y2JmMjg2NDM1MWFmOTg=
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card_deck
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.332
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Perlmutter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-07 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -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