Class: Simplicard::Card

Inherits:
Object
  • Object
show all
Defined in:
lib/simplicard.rb

Constant Summary collapse

ACE =
1
JACK =
11
QUEEN =
12
KING =
13
VALID_VALUES =

VALID_SUITS = [SPADES,CLUBS,DIAMONDS,HEARTS]

[2,3,4,5,6,7,8,9,10,JACK,QUEEN,KING,ACE]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, s) ⇒ Card

Returns a new instance of Card.



60
61
62
63
64
65
# File 'lib/simplicard.rb', line 60

def initialize(value, s)
  @value = value
  # @suit = suit
  @suit = Suit.new(s)
  validation_check
end

Instance Attribute Details

#suitObject (readonly)

this is the facevalue and suit of the card



58
59
60
# File 'lib/simplicard.rb', line 58

def suit
  @suit
end

#valueObject (readonly)

this is the facevalue and suit of the card



58
59
60
# File 'lib/simplicard.rb', line 58

def value
  @value
end

Instance Method Details

#get_suitObject



72
73
74
# File 'lib/simplicard.rb', line 72

def get_suit
  @suit
end

#get_valueObject

this returns the value of the card. Depends on the game, the get_value can return different value than the facevalue



69
70
71
# File 'lib/simplicard.rb', line 69

def get_value
  @value
end

#is_an_ace?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/simplicard.rb', line 105

def is_an_ace?
  return true if @value == ACE
end

#is_face_card?Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
103
# File 'lib/simplicard.rb', line 97

def is_face_card?
  if [JACK,QUEEN,KING].include?(@value)
    return true
  else
    return false
  end
end

#showObject



93
94
95
# File 'lib/simplicard.rb', line 93

def show
  return "#{value_to_s} of #{@suit.suit_to_s}"
end

#value_to_sObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/simplicard.rb', line 77

def value_to_s
  case @value
    when ACE
      "Ace"
    when JACK
      "Jack"
    when QUEEN
      "Queen"
    when KING
      "King"
    else
      @value.to_s
  end

end