Class: Rank

Inherits:
Object
  • Object
show all
Defined in:
lib/rora/model/rank.rb

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", 0)
THREE =
new(3, "3", "Three", 1)
FOUR =
new(5, "4", "Four", 2)
FIVE =
new(7, "5", "Five", 3)
SIX =
new(11, "6", "Six", 4)
SEVEN =
new(13, "7", "Seven", 5)
EIGHT =
new(17, "8", "Eight", 6)
NINE =
new(19, "9", "Nine", 7)
TEN =
new(23, "T", "Ten", 8)
JACK =
new(29, "J", "Jack", 9)
QUEEN =
new(31, "Q", "Queen", 10)
KING =
new(37, "K", "King", 11)
ACE =
new(41, "A", "Ace", 12)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, key, value, order) ⇒ Rank

Returns a new instance of Rank.



13
14
15
16
17
18
# File 'lib/rora/model/rank.rb', line 13

def initialize(id, key, value, order)
  @id = id
  @key = key
  @value = value
  @order = order
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/rora/model/rank.rb', line 11

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/rora/model/rank.rb', line 11

def key
  @key
end

#orderObject (readonly)

Returns the value of attribute order.



11
12
13
# File 'lib/rora/model/rank.rb', line 11

def order
  @order
end

#valueObject (readonly)

Returns the value of attribute value.



11
12
13
# File 'lib/rora/model/rank.rb', line 11

def value
  @value
end

Class Method Details

.get(key) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
# File 'lib/rora/model/rank.rb', line 24

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

.valuesObject



20
21
22
# File 'lib/rora/model/rank.rb', line 20

def self.values
  [TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE]
end

Instance Method Details

#to_sObject



31
32
33
# File 'lib/rora/model/rank.rb', line 31

def to_s
  "Rank: id=#{@id}, key='#{@key}', value='#{@value}'"
end