Class: Rank
Overview
The thirteen different hierarchical values in a deck of cards.
A deck of cards has thirteen ranks: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.
The ranks have a natural order, with the weakest value (0) assigned to the 2 and the strongest value (12) assigned to the ace.
Constant Summary collapse
- TWO =
new(2, "2", "Two", 13)
- THREE =
new(3, "3", "Three", 12)
- FOUR =
new(5, "4", "Four", 11)
- FIVE =
new(7, "5", "Five", 10)
- SIX =
new(11, "6", "Six", 9)
- SEVEN =
new(13, "7", "Seven", 8)
- EIGHT =
new(17, "8", "Eight", 7)
- NINE =
new(19, "9", "Nine", 6)
- TEN =
new(23, "T", "Ten", 5)
- JACK =
new(29, "J", "Jack", 4)
- QUEEN =
new(31, "Q", "Queen", 3)
- KING =
new(37, "K", "King", 2)
- ACE =
new(41, "A", "Ace", 1)
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(rank) ⇒ Object
- #==(rank) ⇒ Object
- #eql?(rank) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(id, key, value, order) ⇒ Rank
constructor
A new instance of Rank.
- #to_s ⇒ Object
Constructor Details
#initialize(id, key, value, order) ⇒ Rank
Returns a new instance of Rank.
15 16 17 18 19 20 |
# File 'lib/rora/model/rank.rb', line 15 def initialize(id, key, value, order) @id = id @key = key @value = value @order = order end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/rora/model/rank.rb', line 13 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
13 14 15 |
# File 'lib/rora/model/rank.rb', line 13 def key @key end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
13 14 15 |
# File 'lib/rora/model/rank.rb', line 13 def order @order end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
13 14 15 |
# File 'lib/rora/model/rank.rb', line 13 def value @value end |
Class Method Details
.get(key) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rora/model/rank.rb', line 26 def self.get(key) self.values.each do |rank| return rank if(rank.key.casecmp(key) == 0) end raise ArgumentError, "No rank exists for key '#{key}'" end |
Instance Method Details
#<=>(rank) ⇒ Object
33 34 35 |
# File 'lib/rora/model/rank.rb', line 33 def <=>(rank) self.order <=> rank.order end |
#==(rank) ⇒ Object
41 42 43 |
# File 'lib/rora/model/rank.rb', line 41 def == rank self.key == rank.key end |
#eql?(rank) ⇒ Boolean
37 38 39 |
# File 'lib/rora/model/rank.rb', line 37 def eql? rank self == rank end |
#hash ⇒ Object
45 46 47 |
# File 'lib/rora/model/rank.rb', line 45 def hash return self.rank.ord end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/rora/model/rank.rb', line 49 def to_s "#{@value}" end |