Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added @card.color
  • Loading branch information
remi committed Jan 20, 2010
1 parent 0336da3 commit 5d0f448
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/playing-cards.rb
Expand Up @@ -4,6 +4,8 @@

class Card

COLORS_FOR_SUITES = { 'club' => :black, 'spade' => :black, 'heart' => :red, 'diamond' => :red }

STANDARD_PLAYING_CARD_NAMES = %w( 2 3 4 5 6 7 8 9 10 Jack Queen King Ace )
STANDARD_PLAYING_CARD_SUITES = %w( Spades Hearts Clubs Diamonds )

Expand All @@ -20,6 +22,10 @@ def initialize name, suite = nil
end
end

def color
Card.color_for(suite)
end

def name= value
@name = value.to_s.strip.sub(/^The\s*/i, '')
end
Expand All @@ -36,6 +42,10 @@ def short_name
"#{ name[0..0].upcase }#{ suite[0..0].upcase }"
end

def self.color_for suite
COLORS_FOR_SUITES[suite]
end

def self.[] name, suite = nil
Card.new name, suite
end
Expand Down Expand Up @@ -66,6 +76,7 @@ def self.suite_from_appreviation abbreviated_suite

def parse name_to_parse
parts = name_to_parse.split('of')
parts = name_to_parse.split('Of') if parts.length == 1

# "Jack of Spades" or "The Jack of Spades"
if parts.length == 2
Expand Down
7 changes: 7 additions & 0 deletions spec/card_spec.rb
Expand Up @@ -2,6 +2,13 @@

describe Card do

it 'has a color (based on suite)' do
TheJackOfSpades.color.should == :black
TheJackOfClubs.color.should == :black
TheJackOfHearts.color.should == :red
TheJackOfDiamonds.color.should == :red
end

it 'has a name, suite, and full_name (eg. "4 of Clubs")' do
card = Card.new 4, :club
card.name.should == '4'
Expand Down
4 changes: 4 additions & 0 deletions spec/solitaire_spec.rb
Expand Up @@ -54,4 +54,8 @@
game.waste.length.should == 3
end

it 'should be able to move the top waste card to a pile (should yell if not allowed)' do
pending 'cards need colors'
end

end

0 comments on commit 5d0f448

Please sign in to comment.