class Brigitte::Card

A Card has a value and sign defined separately.

Note: Compare cards' value with their weight. Cards are only equal if their id's are the same.

Attributes

id[R]
sign[R]
value[R]

Public Class Methods

from_h(card_hash) click to toggle source
# File lib/brigitte/card.rb, line 53
def self.from_h(card_hash)
  return if card_hash.empty?

  new(
    card_hash[:value],
    card_hash[:sign],
    card_hash[:id]
  )
end
new(value, sign, id = nil) click to toggle source
# File lib/brigitte/card.rb, line 16
def initialize(value, sign, id = nil)
  @id = id || SecureRandom.uuid
  @value = value
  @sign = sign
end

Public Instance Methods

==(other) click to toggle source
# File lib/brigitte/card.rb, line 22
def ==(other)
  id == other.id
end
order_level() click to toggle source
# File lib/brigitte/card.rb, line 39
def order_level
  return 15 if @value == '2'

  weight
end
to_h() click to toggle source
# File lib/brigitte/card.rb, line 45
def to_h
  {
    id: id,
    value: value,
    sign: sign
  }
end
to_s() click to toggle source
# File lib/brigitte/card.rb, line 26
def to_s
  value + sign
end
weight() click to toggle source
# File lib/brigitte/card.rb, line 30
def weight
  return 11 if @value == 'J'
  return 12 if @value == 'Q'
  return 13 if @value == 'K'
  return 14 if @value == 'A'

  value.to_i
end