Patterns
Lets start with our simple set card 'Set+*type'. It is an instance of a particular pattern that is connected in code. Currently, it is defined in this file: mod/01_core/set_pattern/03_type.rb
def label name %{All "#{name}" cards} end def prototype_args anchor { :type=>anchor } end def pattern_applies? card !!card.type_id end def anchor_name card card.type_name end def anchor_id card card.type_id end
The codename of *type is 'type', and is actually referenced by the filename itself. Note how the codename appears in the generated version of the above file, in the header as Card::SetType and in the footer as register 'type' ... :
# -*- encoding : utf-8 -*- class Card::TypeSet < Card::SetPattern cattr_accessor :options class << self # ~~~~~~~~~~~ above autogenerated; below pulled from .../mod/01_core/set_pattern/03_type.rb ~~~~~~~~~~~ def label name %{All "#{name}" cards} end def prototype_args anchor { :type=>anchor } end def pattern_applies? card !!card.type_id end def anchor_name card card.type_name end def anchor_id card card.type_id end # ~~~~~~~~~~~ below autogenerated; above pulled from .../mod/01_core/set_pattern/03_type.rb ~~~~~~~~~~~ end register "type", (options || {}) end
The module defines class methods on Card::TypeSet which inherits from Card::SetPattern. This pattern has an anchor, which in the example is the card 'Set', which should be a cardtype card. The card being passed in to anchor_id and anchor_name is the card being tested for membership in the set, and they return values that match the id/name of the pattern anchor (the Set card in the example).
Some sets don't have an anchor, they are global sets like *all or *rstar where we don't have any card parameters to the set. In that case, you do not define anchor_name or anchor_id. Here is an example:
file: .../set_pattern/04_star.rb def label name 'All "*" cards' end def prototype_args anchor { :name=>'*dummy' } end def pattern_applies? card card.cardname.star? end
Here all the work is in pattern_applies? This will be Card::StarSet and register as the 'star' pattern bound to the '*star' Set card.
This is the list of currently standard patterns:
- *all All Cards
- *plus All plus cards (name is not simple?)
- *star All with names beginning with *
- *rstar All cards with rightmost part (tag) beginning with *
- Type+*type All cards with type of 'Type'
- tag+*right All cards with tag of 'tag'
- Type+tag+*type_plus_right All cards whose left part has type 'Type' and has tag of 'tag'
- Any+Card+*self Just this card (Any+Card)
There are many other possible patterns and most of them are very simple to add.