Class: GlimmerKlondikeSolitaire::Model::PlayingCard
- Inherits:
-
Object
- Object
- GlimmerKlondikeSolitaire::Model::PlayingCard
- 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
-
#hidden ⇒ Object
(also: #hidden?)
Returns the value of attribute hidden.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#suit ⇒ Object
readonly
Returns the value of attribute suit.
Class Method Summary collapse
Instance Method Summary collapse
- #color ⇒ Object
-
#initialize(rank, suit, hidden = false) ⇒ PlayingCard
constructor
A new instance of PlayingCard.
- #to_s ⇒ Object
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
#hidden ⇒ Object Also known as:
Returns the value of attribute hidden.
28 29 30 |
# File 'app/glimmer_klondike_solitaire/model/playing_card.rb', line 28 def hidden @hidden end |
#rank ⇒ Object (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 |
#suit ⇒ Object (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
.deck ⇒ Object
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_decks ⇒ Object
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
#color ⇒ Object
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_s ⇒ Object
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 |