class Card
Constants
- FACE_TO_NUM
Attributes
rank[R]
suit[R]
Public Class Methods
new(str)
click to toggle source
# File lib/rpoker/card.rb, line 12 def initialize(str) validate!(str) chars = str.chars @rank = chars.first.upcase @suit = chars.last.downcase end
Public Instance Methods
face?()
click to toggle source
# File lib/rpoker/card.rb, line 24 def face? faces.include? rank end
to_i()
click to toggle source
# File lib/rpoker/card.rb, line 28 def to_i face? ? FACE_TO_NUM[rank] : rank.to_i end
to_s()
click to toggle source
# File lib/rpoker/card.rb, line 20 def to_s "#{rank}#{suit}" end
Private Instance Methods
faces()
click to toggle source
# File lib/rpoker/card.rb, line 57 def faces %w(T J Q K A) end
numerics()
click to toggle source
# File lib/rpoker/card.rb, line 53 def numerics %w(2 3 4 5 6 7 8 9) end
rank?(str)
click to toggle source
# File lib/rpoker/card.rb, line 41 def rank?(str) ranks.include? str.upcase end
ranks()
click to toggle source
# File lib/rpoker/card.rb, line 49 def ranks numerics + faces end
suit?(str)
click to toggle source
# File lib/rpoker/card.rb, line 45 def suit?(str) suits.include? str.downcase end
suits()
click to toggle source
# File lib/rpoker/card.rb, line 61 def suits %w(s c d h) end
validate!(str)
click to toggle source
# File lib/rpoker/card.rb, line 34 def validate!(str) raise ArgumentError, 'Input must be a string' unless str.is_a? String raise ArgumentError, 'Wrong number of characters' unless str.length == 2 raise ArgumentError, 'Input must start with a rank' unless rank?(str[0]) raise ArgumentError, 'Input must end with a suit' unless suit?(str[1]) end