Class: Suit

Inherits:
Object
  • Object
show all
Includes:
Comparable
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(2, "H", "Heart", 1)
DIAMOND =
new(3, "D", "Diamond", 2)
SPADE =
new(5, "S", "Spade", 3)
CLUB =
new(7, "C", "Club", 4)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Suit.



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

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.



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

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#orderObject (readonly)

Returns the value of attribute order.



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

def order
  @order
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.get(key) ⇒ Object

Raises:

  • (ArgumentError)


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

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



19
20
21
# File 'lib/rora/model/suit.rb', line 19

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

Instance Method Details

#<=>(suit) ⇒ Object



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

def <=>(suit)
  self.order <=> suit.order
end

#==(suit) ⇒ Object



38
39
40
# File 'lib/rora/model/suit.rb', line 38

def == suit
  self.key == suit.key
end

#eql?(suit) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rora/model/suit.rb', line 34

def eql? suit
  self == suit
end

#hashObject



42
43
44
# File 'lib/rora/model/suit.rb', line 42

def hash
  return self.key.ord
end

#to_sObject



46
47
48
# File 'lib/rora/model/suit.rb', line 46

def to_s
  "#{@value}s"
end