module Card::Set::Pattern

Each deck can have countless sets of cards, each of which follows one of a small list of patterns. This module provides methods for managing those patterns.

Public Class Methods

codes() click to toggle source

list of codenames of pattern cards @return [Array <Symbol>]

# File lib/card/set/pattern.rb, line 41
def codes
  @codes ||= concrete.map(&:pattern_code).to_set
end
concrete() click to toggle source

Pattern classes all the patterns except for Abstract. They are concrete because they are defined on a set of cards (while abstract sets must be included on them explicitly).

@return [Array <Class>]

# File lib/card/set/pattern.rb, line 12
def concrete
  @concrete ||= []
end
find(pattern_code) click to toggle source

finds pattern class associated with codename e.g. find(:type) returns ‘Card::Set::Type`

@return [Class] pattern class

# File lib/card/set/pattern.rb, line 35
def find pattern_code
  concrete.find { |sub| sub.pattern_code == pattern_code }
end
grouped_codes(with_all: true) click to toggle source

list of lists of codenames in pattern load order @return [Array <Array <Symbol>>]

# File lib/card/set/pattern.rb, line 47
def grouped_codes with_all: true
  g = [[:abstract], nonbase_codes.reverse]
  g.unshift [:all] if with_all
  g
end
ids() click to toggle source

list of ids of pattern cards @return [Array <Integer>]

# File lib/card/set/pattern.rb, line 55
def ids
  @ids ||= concrete.map(&:pattern_id)
end
reloadables() click to toggle source

Pattern classes that can be reloaded without reloading Card (everything but all) @return [Array <Class>]

# File lib/card/set/pattern.rb, line 19
def reloadables
  concrete - [Set::All] + Abstract
end
reset() click to toggle source

remove reloadable sets and prepare for reloading

# File lib/card/set/pattern.rb, line 24
def reset
  reloadables.each do |set_pattern|
    Set.const_remove_if_defined set_pattern.to_s.split("::").last
  end
  @concrete = @codes = @type_assigner_codes = @nonbase_codes = @ids = nil
end

Private Class Methods

nonbase_codes() click to toggle source
# File lib/card/set/pattern.rb, line 61
def nonbase_codes
  @nonbase_codes ||= codes.to_a - [:all]
end