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, #junction_only, #pattern_code, #pattern_id
Instance Method Summary
collapse
anchorless?, generic_label, junction_only?, new, pattern_applies?, register
Constructor Details
#initialize(card) ⇒ Base
Returns a new instance of Base.
8
9
10
11
12
13
|
# File 'lib/card/set/pattern/base.rb', line 8
def initialize card
return if self.class.anchorless?
@anchor_name = self.class.anchor_name(card).to_name
@anchor_id = find_anchor_id card
end
|
Instance Method Details
#anchor_codenames ⇒ Object
38
39
40
41
42
|
# File 'lib/card/set/pattern/base.rb', line 38
def anchor_codenames
anchor_parts.map do |part|
part.cardname&.code || break
end
end
|
#anchor_parts ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/card/set/pattern/base.rb', line 44
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)..-1]
end
end
|
#anchor_parts_count ⇒ Object
56
57
58
|
# File 'lib/card/set/pattern/base.rb', line 56
def anchor_parts_count
self.class.anchor_parts_count
end
|
#find_anchor_id(card) ⇒ Object
15
16
17
|
# File 'lib/card/set/pattern/base.rb', line 15
def find_anchor_id card
self.class.try(:anchor_id, card) || Card.fetch_id(@anchor_name)
end
|
33
34
35
36
|
# File 'lib/card/set/pattern/base.rb', line 33
def format_module_list klass
hash = Card::Set.modules[:nonbase_format][klass]
hash && lookup_module_list(hash)
end
|
#inspect ⇒ Object
68
69
70
|
# File 'lib/card/set/pattern/base.rb', line 68
def inspect
"<#{self.class} #{to_s.to_name.inspect}>"
end
|
#lookup_module_list(modules_hash) ⇒ Object
25
26
27
|
# File 'lib/card/set/pattern/base.rb', line 25
def lookup_module_list modules_hash
module_key && modules_hash[module_key]
end
|
#module_key ⇒ Object
19
20
21
22
23
|
# File 'lib/card/set/pattern/base.rb', line 19
def module_key
return @module_key if defined? @module_key
@module_key = self.class.module_key anchor_codenames
end
|
#module_list ⇒ Object
29
30
31
|
# File 'lib/card/set/pattern/base.rb', line 29
def module_list
lookup_module_list Card::Set.modules[:nonbase]
end
|
#pattern ⇒ Object
60
61
62
|
# File 'lib/card/set/pattern/base.rb', line 60
def pattern
@pattern ||= self.class.pattern
end
|
#rule_set_key ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/card/set/pattern/base.rb', line 77
def rule_set_key
if self.class.anchorless?
self.class.pattern_code.to_s
elsif @anchor_id
"#{@anchor_id}+#{self.class.pattern_code}"
end
end
|
#safe_key ⇒ Object
72
73
74
75
|
# File 'lib/card/set/pattern/base.rb', line 72
def safe_key
caps_part = self.class.pattern_code.to_s.tr(" ", "_").upcase
self.class.anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}"
end
|
#to_s ⇒ Object
64
65
66
|
# File 'lib/card/set/pattern/base.rb', line 64
def to_s
self.class.anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}"
end
|