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.
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deck-of-cards (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ deck-of-cards!
@@ -1,13 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "deck-of-cards/version"
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 = "deck-of-cards"
7
+ s.name = 'deck-of-cards'
7
8
  s.version = DeckOfCards::VERSION
8
- s.authors = ["shannon skipper"]
9
- s.email = ["shannonskipper@gmail.com"]
10
- s.homepage = "https://github.com/Havenwood/deck-of-cards"
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
 
@@ -1,15 +1,21 @@
1
- require_relative 'deck-of-cards/compare_cards'
2
- require_relative 'deck-of-cards/card'
3
- require_relative 'deck-of-cards/version'
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
- suits = %w[Hearts Spades Diamonds Clubs]
11
- ranks = %w[2 3 4 5 6 7 8 9 10 Jack Queen King Ace]
12
- suits.product(ranks) { |suit, rank| @cards << Card.new(rank, suit) }
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.div 2
26
+ @cards.rotate! @cards.count / 2
21
27
  end
22
28
 
23
29
  alias split cut
@@ -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
- end
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
@@ -1,3 +1,3 @@
1
1
  class DeckOfCards
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -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
- require_relative '../lib/deck-of-cards'
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 { |suit| ranks.each { |rank| @correct_cards << Card.new(rank, suit) } }
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.1
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-09-19 00:00:00.000000000 Z
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