lib/hands/card.rb in hands-0.1.0 vs lib/hands/card.rb in hands-0.2.0
- old
+ new
@@ -5,11 +5,11 @@
# `Card[2, :clubs].description` results in `"Two of Clubs"`.
class Card
include Comparable
# @return [Symbol] Card's suit
- # @see SUITES
+ # @see SUITS
attr_accessor :suit
# Card's value
#
# If an invalid value is set, the value will be set to `nil`.
@@ -66,11 +66,11 @@
# Invalid
@value = nil
end
def suit=(suit)
- if (suit.is_a?(String) or suit.is_a?(Symbol)) and SUITES.include?(suit.to_sym)
+ if (suit.is_a?(String) or suit.is_a?(Symbol)) and SUITS.include?(suit.to_sym)
@suit = suit.to_sym
else
@suit = nil
end
end
@@ -86,11 +86,11 @@
end
end
# @return [Boolean] Does the receiver contain a valid value and suit combination
def is_valid?
- SUITES.include?(@suit) and VALUES.include?(@value.to_s.downcase)
+ SUITS.include?(@suit) and VALUES.include?(@value.to_s.downcase)
end
# @return [Boolean] Does the receiver contain an invalid value and suit combination
def is_invalid?
!self.is_valid?
@@ -112,25 +112,25 @@
# By default `check_suit` is `false`. If set to `true`, it will order cards that have the same value by their suit.
#
# @param [Card] other_card the card to compare the receiver to
# @param [Boolean] check_suit a boolean indicating if the suit should be accounted for
# @return [Integer] `-1` if `other_card` is less than the receiver, `0` for equal to, and `1` for greater than
- # @see SUITES
+ # @see SUITS
def <=>(other_card, check_suit = false)
# TODO: Handle invalid cards
result = self.value_index <=> other_card.value_index
return self.suit_index <=> other_card.suit_index if result == 0 and check_suit
result
end
- # Suite's index
+ # Suit's index
#
# Mainly used for internal reasons when comparing cards.
#
# @return [Integer] index of the card's suit
- # @see SUITES
+ # @see SUITS
def suit_index
- SUITES.index(self.suit.downcase)
+ SUITS.index(self.suit.downcase)
end
# Values's index
#
# Mainly used for internal reasons when comparing cards.