Module: Card::Set::Pattern

Defined in:
card/lib/card/set/pattern.rb,
card/lib/card/set/pattern/all.rb,
card/lib/card/set/pattern/base.rb,
card/lib/card/set/pattern/class_methods.rb

Overview

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.

Defined Under Namespace

Modules: All, ClassMethods Classes: Base

Class Method Summary collapse

Class Method Details

.codesArray <Symbol>

list of codenames of pattern cards

Returns:

  • (Array <Symbol>)


41
42
43
# File 'card/lib/card/set/pattern.rb', line 41

def codes
  @codes ||= concrete.map(&:pattern_code).to_set
end

.concreteArray <Class>

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).

Returns:

  • (Array <Class>)


12
13
14
# File 'card/lib/card/set/pattern.rb', line 12

def concrete
  @concrete ||= []
end

.find(pattern_code) ⇒ Class

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

Returns:

  • (Class)

    pattern class



35
36
37
# File 'card/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) ⇒ Array <Array <Symbol>>

list of lists of codenames in pattern load order

Returns:

  • (Array <Array <Symbol>>)


47
48
49
50
51
# File 'card/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

.idsArray <Integer>

list of ids of pattern cards

Returns:

  • (Array <Integer>)


55
56
57
# File 'card/lib/card/set/pattern.rb', line 55

def ids
  @ids ||= concrete.map(&:pattern_id)
end

.reloadablesArray <Class>

Pattern classes that can be reloaded without reloading Card (everything but all)

Returns:

  • (Array <Class>)


19
20
21
# File 'card/lib/card/set/pattern.rb', line 19

def reloadables
  concrete - [Set::All] + Abstract
end

.resetObject

remove reloadable sets and prepare for reloading



24
25
26
27
28
29
# File 'card/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