Class: BetweenTheSheets::Card
- Inherits:
-
Object
- Object
- BetweenTheSheets::Card
- Defined in:
- lib/between_the_sheets/card.rb
Constant Summary collapse
- NAMES =
%w{A 2 3 4 5 6 7 8 9 10 J Q K JOKER}.freeze
- SUITS =
%w{clubs diamonds hearts spades}.freeze
- SUIT_COLORS =
{ clubs: :white, diamonds: :red, hearts: :red, spades: :white }.freeze
- IMAGES =
{ clubs: "\u2664", hearts: "\u2661", diamonds: "\u2662", spades: "\u2667" }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#suit ⇒ Object
readonly
Returns the value of attribute suit.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize ⇒ Card
constructor
A new instance of Card.
- #joker? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/between_the_sheets/card.rb', line 29 def name @name end |
#suit ⇒ Object (readonly)
Returns the value of attribute suit.
29 30 31 |
# File 'lib/between_the_sheets/card.rb', line 29 def suit @suit end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
29 30 31 |
# File 'lib/between_the_sheets/card.rb', line 29 def value @value end |
Class Method Details
.draw(*skip_cards) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/between_the_sheets/card.rb', line 38 def self.draw(*skip_cards) return Card.new if skip_cards.empty? loop do card = Card.new break card unless skip_cards.include? card.id end end |
.value(name) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/between_the_sheets/card.rb', line 47 def self.value(name) case name when "A" 1 when "J" 11 when "Q" 12 when "K" 13 when "JOKER" 0 else NAMES.index(name) + 1 end end |
Instance Method Details
#id ⇒ Object
70 71 72 |
# File 'lib/between_the_sheets/card.rb', line 70 def id (Digest::MD5.new << self.to_s).to_s end |
#joker? ⇒ Boolean
74 75 76 |
# File 'lib/between_the_sheets/card.rb', line 74 def joker? @name == "JOKER" end |
#to_s ⇒ Object
64 65 66 67 68 |
# File 'lib/between_the_sheets/card.rb', line 64 def to_s # The space at the end is intentional to pad the image with the # next character. "#{@name}#{@image.colorize(SUIT_COLORS[@suit.to_sym])} " end |