Class: Card::Set::Pattern::Base
- Inherits:
-
Object
- Object
- Card::Set::Pattern::Base
- Defined in:
- lib/card/set/pattern/base.rb
Overview
class from which set patterns inherit
Direct Known Subclasses
Class Attribute Summary collapse
- .anchor_parts_count ⇒ Object
-
.anchorless ⇒ Object
Returns the value of attribute anchorless.
-
.assigns_type ⇒ Object
Returns the value of attribute assigns_type.
-
.junction_only ⇒ Object
Returns the value of attribute junction_only.
-
.pattern_code ⇒ Object
Returns the value of attribute pattern_code.
-
.pattern_id ⇒ Object
Returns the value of attribute pattern_id.
Class Method Summary collapse
- .anchorless? ⇒ Boolean
-
.generic_label ⇒ Object
label for set pattern if no anchor is given.
- .junction_only? ⇒ Boolean
- .module_key(anchor_codes) ⇒ Object
- .new(card) ⇒ Object
- .pattern ⇒ Object
- .pattern_applies?(card) ⇒ Boolean
- .register(pattern_code, opts = {}) ⇒ Object
Instance Method Summary collapse
- #anchor_codenames ⇒ Object
- #anchor_parts ⇒ Object
- #anchor_parts_count ⇒ Object
- #find_anchor_id(card) ⇒ Object
- #format_module_list(klass) ⇒ Object
-
#initialize(card) ⇒ Base
constructor
Instance methods.
- #inspect ⇒ Object
- #lookup_module_list(modules_hash) ⇒ Object
- #module_key ⇒ Object
- #module_list ⇒ Object
- #pattern ⇒ Object
- #rule_set_key ⇒ Object
- #safe_key ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(card) ⇒ Base
Instance methods
61 62 63 64 65 |
# File 'lib/card/set/pattern/base.rb', line 61 def initialize card return if self.class.anchorless? @anchor_name = self.class.anchor_name(card).to_name @anchor_id = find_anchor_id card end |
Class Attribute Details
.anchor_parts_count ⇒ Object
42 43 44 |
# File 'lib/card/set/pattern/base.rb', line 42 def anchor_parts_count @anchor_parts_count ||= (anchorless? ? 0 : 1) end |
.anchorless ⇒ Object
Returns the value of attribute anchorless.
7 8 9 |
# File 'lib/card/set/pattern/base.rb', line 7 def anchorless @anchorless end |
.assigns_type ⇒ Object
Returns the value of attribute assigns_type.
7 8 9 |
# File 'lib/card/set/pattern/base.rb', line 7 def assigns_type @assigns_type end |
.junction_only ⇒ Object
Returns the value of attribute junction_only.
7 8 9 |
# File 'lib/card/set/pattern/base.rb', line 7 def junction_only @junction_only end |
.pattern_code ⇒ Object
Returns the value of attribute pattern_code.
7 8 9 |
# File 'lib/card/set/pattern/base.rb', line 7 def pattern_code @pattern_code end |
.pattern_id ⇒ Object
Returns the value of attribute pattern_id.
7 8 9 |
# File 'lib/card/set/pattern/base.rb', line 7 def pattern_id @pattern_id end |
Class Method Details
.anchorless? ⇒ Boolean
30 31 32 |
# File 'lib/card/set/pattern/base.rb', line 30 def anchorless? anchorless end |
.generic_label ⇒ Object
label for set pattern if no anchor is given
54 55 56 |
# File 'lib/card/set/pattern/base.rb', line 54 def generic_label label nil end |
.junction_only? ⇒ Boolean
26 27 28 |
# File 'lib/card/set/pattern/base.rb', line 26 def junction_only? junction_only == true end |
.module_key(anchor_codes) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/card/set/pattern/base.rb', line 46 def module_key anchor_codes return pattern_code.to_s.camelize if anchorless? return unless anchor_codes # is this not an error? ([pattern_code] + anchor_codes).map { |code| code.to_s.camelize }.join "::" end |
.new(card) ⇒ Object
11 12 13 |
# File 'lib/card/set/pattern/base.rb', line 11 def new card super if pattern_applies? card end |
.pattern ⇒ Object
34 35 36 |
# File 'lib/card/set/pattern/base.rb', line 34 def pattern Card.fetch(pattern_id, skip_modules: true).name end |
.pattern_applies?(card) ⇒ Boolean
38 39 40 |
# File 'lib/card/set/pattern/base.rb', line 38 def pattern_applies? card junction_only? ? card.name.junction? : true end |
.register(pattern_code, opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/card/set/pattern/base.rb', line 15 def register pattern_code, opts={} if (self.pattern_id = Card::Codename.id(pattern_code)) self.pattern_code = pattern_code Card.set_patterns.insert opts.delete(:index).to_i, self self.anchorless = !respond_to?(:anchor_name) opts.each { |key, val| send "#{key}=", val } else warn "no codename for pattern_code #{pattern_code}" end end |
Instance Method Details
#anchor_codenames ⇒ Object
89 90 91 92 93 94 |
# File 'lib/card/set/pattern/base.rb', line 89 def anchor_codenames anchor_parts.map do |part| part_id = Card.fetch_id part Card::Codename[part_id] || break end end |
#anchor_parts ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/card/set/pattern/base.rb', line 96 def anchor_parts return [@anchor_name] unless anchor_parts_count > 1 parts = @anchor_name.parts if parts.size <= anchor_parts_count parts else # handles cases where anchor is a compound card, eg A+B+*self [@anchor_name[0..-anchor_parts_count]] + parts[(-anchor_parts_count + 1)..-1] end end |
#anchor_parts_count ⇒ Object
108 109 110 |
# File 'lib/card/set/pattern/base.rb', line 108 def anchor_parts_count self.class.anchor_parts_count end |
#find_anchor_id(card) ⇒ Object
67 68 69 |
# File 'lib/card/set/pattern/base.rb', line 67 def find_anchor_id card self.class.try(:anchor_id, card) || Card.fetch_id(@anchor_name) end |
#format_module_list(klass) ⇒ Object
84 85 86 87 |
# File 'lib/card/set/pattern/base.rb', line 84 def format_module_list klass hash = Card::Set.modules[:nonbase_format][klass] hash && lookup_module_list(hash) end |
#inspect ⇒ Object
120 121 122 |
# File 'lib/card/set/pattern/base.rb', line 120 def inspect "<#{self.class} #{to_s.to_name.inspect}>" end |
#lookup_module_list(modules_hash) ⇒ Object
76 77 78 |
# File 'lib/card/set/pattern/base.rb', line 76 def lookup_module_list modules_hash module_key && modules_hash[module_key] end |
#module_key ⇒ Object
71 72 73 74 |
# File 'lib/card/set/pattern/base.rb', line 71 def module_key return @module_key if defined? @module_key @module_key = self.class.module_key anchor_codenames end |
#module_list ⇒ Object
80 81 82 |
# File 'lib/card/set/pattern/base.rb', line 80 def module_list lookup_module_list Card::Set.modules[:nonbase] end |
#pattern ⇒ Object
112 113 114 |
# File 'lib/card/set/pattern/base.rb', line 112 def pattern @pattern ||= self.class.pattern end |
#rule_set_key ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/card/set/pattern/base.rb', line 129 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
124 125 126 127 |
# File 'lib/card/set/pattern/base.rb', line 124 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
116 117 118 |
# File 'lib/card/set/pattern/base.rb', line 116 def to_s self.class.anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}" end |