Module: Cardname::Pieces

Included in:
Cardname
Defined in:
cardname/lib/cardname/pieces.rb

Overview

Cards never have more than two “parts” (left and right), but they can have many “pieces”. A card’s pieces are all the other cards whose existence its existence implies. For example if A+B+C exists, that implies that A, B, C, and A+B do too.

Instance Method Summary collapse

Instance Method Details

#ancestorsObject



18
19
20
# File 'cardname/lib/cardname/pieces.rb', line 18

def ancestors
  pieces.reject { |p| p == self }
end

#piece_namesObject



14
15
16
# File 'cardname/lib/cardname/pieces.rb', line 14

def piece_names
  pieces.map(&:to_name)
end

#piecesObject

self and all ancestors (= parts and recursive lefts)

Examples:

"A+B+C+D".to_name.pieces
# => ["A", "B", "C", "D", "A+B", "A+B+C", "A+B+C+D"]


10
11
12
# File 'cardname/lib/cardname/pieces.rb', line 10

def pieces
  simple? ? [self] : (parts + junction_pieces)
end