Class: FiftyTwo::Rank
- Inherits:
-
Object
- Object
- FiftyTwo::Rank
- Includes:
- Comparable
- Defined in:
- lib/fiftytwo/rank.rb
Constant Summary collapse
- CATEGORIES =
%i[pip face]
- ALL =
[ TWO = Rank.new(2).freeze, THREE = Rank.new(3).freeze, FOUR = Rank.new(4).freeze, FIVE = Rank.new(5).freeze, SIX = Rank.new(6).freeze, SEVEN = Rank.new(7).freeze, EIGHT = Rank.new(8).freeze, NINE = Rank.new(9).freeze, TEN = Rank.new(10).freeze, JACK = Rank.new(11, "jack", :face).freeze, QUEEN = Rank.new(12, "queen", :face).freeze, KING = Rank.new(13, "king", :face).freeze, ACE = Rank.new(14, "ace").freeze ]
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #ace? ⇒ Boolean
- #identifier ⇒ Object (also: #code)
-
#initialize(value, name = nil, category = :pip) ⇒ Rank
constructor
A new instance of Rank.
- #to_s ⇒ Object
Constructor Details
#initialize(value, name = nil, category = :pip) ⇒ Rank
Returns a new instance of Rank.
10 11 12 13 14 |
# File 'lib/fiftytwo/rank.rb', line 10 def initialize(value, name = nil, category = :pip) @value = value @name = name || value.to_s @category = category end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
8 9 10 |
# File 'lib/fiftytwo/rank.rb', line 8 def category @category end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/fiftytwo/rank.rb', line 8 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/fiftytwo/rank.rb', line 8 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
44 45 46 |
# File 'lib/fiftytwo/rank.rb', line 44 def <=>(other) value <=> other.value end |
#ace? ⇒ Boolean
40 41 42 |
# File 'lib/fiftytwo/rank.rb', line 40 def ace? name == "ace" end |
#identifier ⇒ Object Also known as: code
52 53 54 |
# File 'lib/fiftytwo/rank.rb', line 52 def identifier name.to_i > 0 ? name : name[0].upcase end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/fiftytwo/rank.rb', line 48 def to_s name.titleize end |