Class: GlimmerKlondikeSolitaire::Model::PlayingCard

Inherits:
Object
  • Object
show all
Defined in:
app/glimmer_klondike_solitaire/model/playing_card.rb

Constant Summary collapse

SUITS =
[:spades, :hearts, :clubs, :diamonds]
BLACK_SUITS =
[:spades, :clubs]
RED_SUITS =
[:hearts, :diamonds]
RANK_COUNT =
13

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rank, suit, hidden = false) ⇒ PlayingCard

Returns a new instance of PlayingCard.



31
32
33
34
35
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 31

def initialize(rank, suit, hidden = false)
  @rank = rank
  @suit = suit
  @hidden = hidden
end

Instance Attribute Details

#hiddenObject Also known as: hidden?

Returns the value of attribute hidden.



28
29
30
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 28

def hidden
  @hidden
end

#rankObject (readonly)

Returns the value of attribute rank.



27
28
29
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 27

def rank
  @rank
end

#suitObject (readonly)

Returns the value of attribute suit.



27
28
29
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 27

def suit
  @suit
end

Class Method Details

.deckObject



10
11
12
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 10

def deck
  suit_decks.flatten
end

.suit_deck(suit) ⇒ Object



20
21
22
23
24
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 20

def suit_deck(suit)
  1.upto(RANK_COUNT).map do |rank|
    new(rank, suit)
  end
end

.suit_decksObject



14
15
16
17
18
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 14

def suit_decks
  SUITS.map do |suit|
    suit_deck(suit)
  end
end

Instance Method Details

#colorObject



37
38
39
40
41
42
43
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 37

def color
  if BLACK_SUITS.include?(suit)
    :black
  elsif RED_SUITS.include?(suit)
    :red
  end
end

#to_sObject



45
46
47
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 45

def to_s
  "Playing Card #{rank}#{suit.to_s[0].upcase}"
end