Class: Card::Set::Pattern::Base
- Inherits:
-
Object
- Object
- Card::Set::Pattern::Base
show all
- Extended by:
- ClassMethods
- Defined in:
- lib/card/set/pattern/base.rb
Overview
class from which set patterns inherit
Instance Attribute Summary
Attributes included from ClassMethods
#anchorless, #assigns_type, #compound_only, #pattern_code
Instance Method Summary
collapse
anchorless?, compound_only?, generic_label, new, pattern, pattern_applies?, pattern_id, register
Constructor Details
#initialize(card) ⇒ Base
Returns a new instance of Base.
9
10
11
12
13
14
|
# File 'lib/card/set/pattern/base.rb', line 9
def initialize card
return if anchorless?
@anchor_name = self.class.anchor_name(card).to_name
@anchor_id = find_anchor_id card
end
|
Instance Method Details
#anchor_codenames ⇒ Object
39
40
41
42
43
|
# File 'lib/card/set/pattern/base.rb', line 39
def anchor_codenames
anchor_parts.map do |part|
part.cardname&.codename || break
end
end
|
#anchor_parts ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/card/set/pattern/base.rb', line 49
def anchor_parts
return [@anchor_name] unless anchor_parts_count > 1
parts = @anchor_name.parts
if parts.size <= anchor_parts_count
parts
else
[@anchor_name[0..-anchor_parts_count]] + parts[(-anchor_parts_count + 1)..]
end
end
|
#anchor_parts_count ⇒ Object
45
46
47
|
# File 'lib/card/set/pattern/base.rb', line 45
def anchor_parts_count
@anchor_parts_count ||= self.class.anchor_parts_count @anchor_name
end
|
#find_anchor_id(card) ⇒ Object
16
17
18
|
# File 'lib/card/set/pattern/base.rb', line 16
def find_anchor_id card
self.class.try(:anchor_id, card) || @anchor_name.card_id
end
|
34
35
36
37
|
# File 'lib/card/set/pattern/base.rb', line 34
def format_module_list klass
hash = Card::Set.modules[:nonbase_format][klass]
hash && lookup_module_list(hash)
end
|
#inspect ⇒ Object
65
66
67
|
# File 'lib/card/set/pattern/base.rb', line 65
def inspect
"<#{self.class} #{to_s.to_name.inspect}>"
end
|
#lookup_module_list(modules_hash) ⇒ Object
26
27
28
|
# File 'lib/card/set/pattern/base.rb', line 26
def lookup_module_list modules_hash
module_key && modules_hash[module_key]
end
|
#module_key ⇒ Object
20
21
22
23
24
|
# File 'lib/card/set/pattern/base.rb', line 20
def module_key
return @module_key if defined? @module_key
@module_key = self.class.module_key anchor_codenames
end
|
#module_list ⇒ Object
30
31
32
|
# File 'lib/card/set/pattern/base.rb', line 30
def module_list
lookup_module_list Card::Set.modules[:nonbase]
end
|
#rule_lookup_key ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/card/set/pattern/base.rb', line 74
def rule_lookup_key
if anchorless?
pattern_code.to_s
elsif @anchor_id
"#{@anchor_id}+#{pattern_code}"
end
end
|
#safe_key ⇒ Object
69
70
71
72
|
# File 'lib/card/set/pattern/base.rb', line 69
def safe_key
caps_part = pattern_code.to_s.tr(" ", "_").upcase
anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}"
end
|
#to_s ⇒ Object
61
62
63
|
# File 'lib/card/set/pattern/base.rb', line 61
def to_s
anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}"
end
|