Class: FiftyTwo::Rank

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#categoryObject (readonly)

Returns the value of attribute category.



8
9
10
# File 'lib/fiftytwo/rank.rb', line 8

def category
  @category
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/fiftytwo/rank.rb', line 8

def name
  @name
end

#valueObject (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

Returns:

  • (Boolean)


40
41
42
# File 'lib/fiftytwo/rank.rb', line 40

def ace?
  name == "ace"
end

#identifierObject 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_sObject



48
49
50
# File 'lib/fiftytwo/rank.rb', line 48

def to_s
  name.titleize
end