Class: Suit

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

Overview

The four categories in a deck of cards.

Each card bears one of four symbols showing which suit it belongs to. A deck of cards has four suits: hearts, clubs, spades, and diamonds.

Constant Summary collapse

HEART =
new(43, "H", "Heart")
SPADE =
new(47, "S", "Spade")
CLUB =
new(53, "C", "Club")
DIAMOND =
new(59, "D", "Diamond")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, key, value) ⇒ Suit

Returns a new instance of Suit.



10
11
12
13
14
# File 'lib/rora/model/suit.rb', line 10

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/rora/model/suit.rb', line 8

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/rora/model/suit.rb', line 8

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/rora/model/suit.rb', line 8

def value
  @value
end

Class Method Details

.get(key) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File 'lib/rora/model/suit.rb', line 20

def self.get(key)
  self.values.each do |suit|
    return suit if suit.key.casecmp(key) == 0
  end
  raise ArgumentError, "No suit exists for key " + key
end

.valuesObject



16
17
18
# File 'lib/rora/model/suit.rb', line 16

def self.values
  [HEART, SPADE, CLUB, DIAMOND]
end

Instance Method Details

#==(suit) ⇒ Object



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

def == suit
  self.id == suit.id
end

#to_sObject



27
28
29
# File 'lib/rora/model/suit.rb', line 27

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