card_deck 2.0.1 → 2.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +1 -0
  3. data/lib/card.rb +29 -48
  4. data/lib/deck.rb +3 -5
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjIzYzI2NWIzYTQwNGIxZjlkODRlOWJhNzgwNmYzODEzODYzNDJmYw==
4
+ YWY5ZjY4ZDA2ZjI4YjYwNDc5NTQwOTc3ZWFmYjcyYjQ5MDdiZmNlNQ==
5
5
  data.tar.gz: !binary |-
6
- MmJiZDRkODljZjVhMWMzNTFjYjJmMzg4NTIyM2ViYzUxZDQ2MGEzMg==
6
+ YzEwMGFkZTUzNDc4ZWE5Nzg0NGE2YzgyMThmNzBhOWNkZjZiNjQ0NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTFjNzY1YjNjYjAwNzI2ZTIwNDgxMDg0MzFjZmI3YmI0NGY3YzI4NjdlMDI3
10
- OTYzOGJjY2FlOWI2NGNiYzBiY2Y4NDljZTY3NmExYTIzY2ZkMjg4YTUzMGE3
11
- YWE2ZDBkYWMxZmFkMjVjMzc1ZmVlMzdkMGE4YjMxMjdkZjRhNGI=
9
+ ZWY0Yjc0M2Y5NjBmZTU4NmJhNGVhMTRkNDRmMmY3NTAwMzFmNGJjYWFjZTIx
10
+ NjBmNDMyYzJlNzBjMDg1NTUzMGVkZDFkMTZhNzE0NjhkZGM2M2ZiYWNiYWEy
11
+ MWEwZmNlNzU1ODYyODJmNmM2MjE2MmU3ZDg0NjY2MmI4MDExZGQ=
12
12
  data.tar.gz: !binary |-
13
- MzYzODFlZTUxNzQ1YWJjMjBkNjcxODYwZmE1NWMxMjQ5MjQ1NzNjNWU4Mzc1
14
- MDAxYzRiNmUwN2Y5YjFjZWIxZjg0MWJhZWEzNTdkN2NiNDc2NmFjMDU3Yjdh
15
- OTdmZDZiODY2ZDYzMjU0MmU1NGMyY2NjMWM5YWM3MzhiYTY5Yjg=
13
+ YTgyNmE4NjYxMzdhY2Y0YzgxMzEzYWUxMzc4OTAwODIzNmQ4NjFlZmYzMjU3
14
+ MmJkNTdkOTVkYjAzNWFmN2MyYTk5MGQ4YzE5NTAyYzJkZTQxZGUzYjA5Njg1
15
+ ZTUzMzZmYjQ4ZjFmNDkyNTgyMWUxMDFkNGFhMjZkNTM4Y2QxYmI=
data/README.md CHANGED
@@ -8,3 +8,4 @@ Can include jokers
8
8
  [![Code Climate](https://codeclimate.com/github/Zrp200/card_deck/badges/gpa.svg)](https://codeclimate.com/github/Zrp200/card_deck)
9
9
  [![Build Status](https://travis-ci.org/Zrp200/card_deck.svg?branch=master)](https://travis-ci.org/Zrp200/card_deck)
10
10
  [![Test Coverage](https://codeclimate.com/github/Zrp200/card_deck/badges/coverage.svg)](https://codeclimate.com/github/Zrp200/card_deck)
11
+ [![Dependency Status](https://gemnasium.com/Zrp200/card_deck.svg)](https://gemnasium.com/Zrp200/card_deck)
data/lib/card.rb CHANGED
@@ -1,55 +1,36 @@
1
- # The gem
2
- module CardDeck
3
- def Card(num, suit=nil) # an easier way to generate a card
4
- Card.new num, suit
5
- end
6
- # Errors for when you incorrectly use a card.
7
- class CardError < StandardError; end
8
- class Card # The central part of any card game. It is what makes card games 'Card' games.
9
- # Suits
10
- HEARTS, SPADES, DIAMONDS, CLUBS = "\u2665", "\u2660", "\u2666", "\u2663"
11
- # Legal arguments for parameter num in Card#new.
12
- NUM = %w(Ace King Queen Jack Joker) + (2..10).to_a
13
- # Legal arguments for parameter suit in Card#new
14
- SUIT = [HEARTS, SPADES, DIAMONDS, CLUBS]
15
- # The card's number. Must be Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, or Joker
16
- attr_accessor :num
17
- # The card's suit. Must be Spades, Diamonds, Clubs, Hearts, or nil.
18
- attr_accessor :suit
19
- # Creates a new card. Parameter num is the card's number. Parameter suit is the card's suit
20
- def initialize(num, suit=nil)
21
- unless suit.nil?
22
- suit = case suit.downcase
23
- when "diamonds" then DIAMONDS
24
- when "spades" then SPADES
25
- when "hearts" then HEARTS
26
- when "clubs" then CLUBS
27
- end
28
- end
29
- unless NUM.include?(num) || SUIT.include?(suit) || suit.nil?
30
- raise CardError, 'Illegal argument'
31
- else
32
- @num, @suit = num, suit
33
- end
1
+ module CardDeck # The gem
2
+ def Card(num, suit); Card.new num, suit; end # an easier way to generate a card
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) + (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
+ 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
+ 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 SUIT.include? suit
12
+ suit = case suit.downcase
13
+ when "diamonds" then DIAMONDS
14
+ when "spades" then SPADES
15
+ when "hearts" then HEARTS
16
+ when "clubs" then CLUBS
34
17
  end
35
- def self.gen # Creates a random new card.
36
- self.new NUM.sample, SUIT.sample
37
18
  end
38
- def abbreviation # The shorter representation of the card
39
- unless @num == "Joker"
40
- if @num == 10 then "#{@suit}#{@num}"
41
- else
42
- "#{@suit}#{(@num.to_s)[0]}"
43
- end
19
+ @num, @suit = num, suit
20
+ end
21
+ def self.gen; self.new NUM.sample, SUIT.sample; end # Creates a random new card.
22
+ def abbreviation # The shorter representation of the card
23
+ unless @num == "Joker"
24
+ if @num == 10 then "#{@suit}#{@num}"
44
25
  else
45
- @num
26
+ "#{@suit}#{(@num.to_s)[0]}"
46
27
  end
28
+ else
29
+ @num
47
30
  end
48
- def black? # Tests if the suit color is black
49
- suit == SPADES || suit == CLUBS
50
- end
51
- alias abbr abbreviation # A shorter method name
52
- alias to_s abbr
53
- alias inspect abbr
54
31
  end
32
+ def black?; suit == SPADES || suit == CLUBS; end # Tests if the suit color is black
33
+ alias abbr abbreviation # A shorter method name
34
+ alias to_s abbr
55
35
  end
36
+ end
data/lib/deck.rb CHANGED
@@ -1,14 +1,12 @@
1
1
  require_relative "card.rb"
2
2
  module CardDeck
3
3
  class Deck # The deck
4
- # The cards in the deck
5
- attr_accessor :cards
6
- alias inspect cards
4
+ attr_accessor :cards # The cards in the deck
7
5
  def initialize(args=Hash.new(false)) # Creates a new Deck. Includes Jokers when parmeter args == {jokers: true}
8
6
  @cards = Array.new
9
7
  for suit in Card::SUIT
10
8
  stock 'Ace', suit
11
- for num in (2..10).to_a; stock num, suit; end
9
+ for num in (2..10).to_a; stock num, suit; end
12
10
  stock 'Jack', suit
13
11
  stock 'Queen', suit
14
12
  stock 'King', suit
@@ -16,6 +14,6 @@ module CardDeck
16
14
  2.times {stock 'Joker'} if args[:jokers]
17
15
  end
18
16
  private
19
- def stock(num, suit=nil); @cards.push Card.new num, suit; end # Creates a Card to add to Deck#cards
17
+ def stock(num, suit=Card::SUIT.sample); @cards.push Card.new num, suit; end # Creates a Card to add to Deck#cards
20
18
  end
21
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: 2.0.1
4
+ version: 2.1.pre
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-11-17 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -67,9 +67,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - ! '>='
70
+ - - ! '>'
71
71
  - !ruby/object:Gem::Version
72
- version: '0'
72
+ version: 1.3.1
73
73
  requirements: []
74
74
  rubyforge_project:
75
75
  rubygems_version: 2.4.2