Module: Card::Mark

Included in:
Card
Defined in:
lib/card/mark.rb

Overview

Card::Mark provides class methods for Card to translate all different kind of card identifiers to card objects.

Instance Method Summary collapse

Instance Method Details

#cardish(cardish) ⇒ Object

translates marks (and other inputs) into a Card

Parameters:

Returns:

  • Card



9
10
11
12
13
14
15
# File 'lib/card/mark.rb', line 9

def cardish cardish
  if cardish.is_a? Card
    cardish
  else
    fetch cardish, new: {}
  end
end

#id_or_name(parts) ⇒ Integer or Card::Name

translates various inputs into either an id or a name.

Parameters:

  • parts (Array<Symbol, Integer, String, Card::Name, Card>)

    a mark or mark parts

Returns:



20
21
22
23
24
# File 'lib/card/mark.rb', line 20

def id_or_name parts
  mark = parts.flatten
  mark = mark.first if mark.size <= 1
  id_from_mark(mark) || Card::Name[mark]
end