Module: Card::Set::Pattern::ClassMethods

Included in:
Base
Defined in:
lib/card/set/pattern/class_methods.rb

Overview

methods for Set::Pattern classes

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#anchor_parts_countObject



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

def anchor_parts_count
  @anchor_parts_count ||= (anchorless? ? 0 : 1)
end

#anchorlessObject

Returns the value of attribute anchorless.



6
7
8
# File 'lib/card/set/pattern/class_methods.rb', line 6

def anchorless
  @anchorless
end

#assigns_typeObject

Returns the value of attribute assigns_type.



6
7
8
# File 'lib/card/set/pattern/class_methods.rb', line 6

def assigns_type
  @assigns_type
end

#compound_onlyObject

Returns the value of attribute compound_only.



6
7
8
# File 'lib/card/set/pattern/class_methods.rb', line 6

def compound_only
  @compound_only
end

#pattern_codeObject

Returns the value of attribute pattern_code.



6
7
8
# File 'lib/card/set/pattern/class_methods.rb', line 6

def pattern_code
  @pattern_code
end

Instance Method Details

#anchorless?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/card/set/pattern/class_methods.rb', line 24

def anchorless?
  anchorless
end

#compound_only?Boolean

Returns:

  • (Boolean)


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

def compound_only?
  compound_only == true
end

#generic_labelObject

label for set pattern if no anchor is given



53
54
55
# File 'lib/card/set/pattern/class_methods.rb', line 53

def generic_label
  label nil
end

#module_key(anchor_codes) ⇒ Object



45
46
47
48
49
50
# File 'lib/card/set/pattern/class_methods.rb', line 45

def module_key anchor_codes
  return pattern_code.to_s.camelize if anchorless?
  return unless anchor_codes # not all anchors have codenames

  ([pattern_code] + anchor_codes).map { |code| code.to_s.camelize }.join "::"
end

#new(card) ⇒ Object



9
10
11
# File 'lib/card/set/pattern/class_methods.rb', line 9

def new card
  super if pattern_applies? card
end

#patternObject

TODO: change to #name or #pattern_name



33
34
35
# File 'lib/card/set/pattern/class_methods.rb', line 33

def pattern
  pattern_id.cardname
end

#pattern_applies?(card) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/card/set/pattern/class_methods.rb', line 37

def pattern_applies? card
  compound_only? ? card.name.compound? : true
end

#pattern_idObject



28
29
30
# File 'lib/card/set/pattern/class_methods.rb', line 28

def pattern_id
  pattern_code.card_id
end

#register(pattern_code, opts = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/card/set/pattern/class_methods.rb', line 13

def register pattern_code, opts={}
  self.pattern_code = pattern_code
  Pattern.concrete.insert opts.delete(:index).to_i, self
  self.anchorless = !respond_to?(:anchor_name)
  opts.each { |key, val| send "#{key}=", val }
end