Class: Card::Set::Pattern::Abstract
- Inherits:
-
Object
- Object
- Card::Set::Pattern::Abstract
- Defined in:
- lib/card/set_pattern.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.anchor_parts_count ⇒ Object
Returns the value of attribute anchor_parts_count.
-
.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
- .junction_only? ⇒ Boolean
- .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
- #format_module_list(klass) ⇒ Object
-
#initialize(card) ⇒ Abstract
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) ⇒ Abstract
Instance methods
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/card/set_pattern.rb', line 85 def initialize card unless self.class.anchorless? @anchor_name = self.class.anchor_name(card).to_name @anchor_id = if self.class.respond_to? :anchor_id self.class.anchor_id card else Card.fetch_id @anchor_name end end self end |
Class Attribute Details
.anchor_parts_count ⇒ Object
Returns the value of attribute anchor_parts_count.
44 45 46 |
# File 'lib/card/set_pattern.rb', line 44 def anchor_parts_count @anchor_parts_count end |
.anchorless ⇒ Object
Returns the value of attribute anchorless.
44 45 46 |
# File 'lib/card/set_pattern.rb', line 44 def anchorless @anchorless end |
.assigns_type ⇒ Object
Returns the value of attribute assigns_type.
44 45 46 |
# File 'lib/card/set_pattern.rb', line 44 def assigns_type @assigns_type end |
.junction_only ⇒ Object
Returns the value of attribute junction_only.
44 45 46 |
# File 'lib/card/set_pattern.rb', line 44 def junction_only @junction_only end |
.pattern_code ⇒ Object
Returns the value of attribute pattern_code.
44 45 46 |
# File 'lib/card/set_pattern.rb', line 44 def pattern_code @pattern_code end |
.pattern_id ⇒ Object
Returns the value of attribute pattern_id.
44 45 46 |
# File 'lib/card/set_pattern.rb', line 44 def pattern_id @pattern_id end |
Class Method Details
.anchorless? ⇒ Boolean
66 67 68 |
# File 'lib/card/set_pattern.rb', line 66 def anchorless? !!anchorless end |
.junction_only? ⇒ Boolean
62 63 64 |
# File 'lib/card/set_pattern.rb', line 62 def junction_only? junction_only == true end |
.new(card) ⇒ Object
47 48 49 |
# File 'lib/card/set_pattern.rb', line 47 def new card super if pattern_applies? card end |
.pattern ⇒ Object
70 71 72 |
# File 'lib/card/set_pattern.rb', line 70 def pattern Card.fetch(pattern_id, skip_modules: true).cardname end |
.pattern_applies?(card) ⇒ Boolean
74 75 76 |
# File 'lib/card/set_pattern.rb', line 74 def pattern_applies? card junction_only? ? card.cardname.junction? : true end |
.register(pattern_code, opts = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/card/set_pattern.rb', line 51 def register pattern_code, opts={} if (self.pattern_id = Card::Codename[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
126 127 128 129 130 131 |
# File 'lib/card/set_pattern.rb', line 126 def anchor_codenames anchor_parts.map do |part| part_id = Card.fetch_id part part_id && Card::Codename[part_id.to_i] || (return nil) end end |
#anchor_parts ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/card/set_pattern.rb', line 133 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
144 145 146 |
# File 'lib/card/set_pattern.rb', line 144 def anchor_parts_count self.class.anchor_parts_count end |
#format_module_list(klass) ⇒ Object
121 122 123 124 |
# File 'lib/card/set_pattern.rb', line 121 def format_module_list klass hash = Card::Set.modules[:nonbase_format][klass] hash && lookup_module_list(hash) end |
#inspect ⇒ Object
156 157 158 |
# File 'lib/card/set_pattern.rb', line 156 def inspect "<#{self.class} #{to_s.to_name.inspect}>" end |
#lookup_module_list(modules_hash) ⇒ Object
113 114 115 |
# File 'lib/card/set_pattern.rb', line 113 def lookup_module_list modules_hash module_key && modules_hash[module_key] end |
#module_key ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/card/set_pattern.rb', line 97 def module_key if defined? @module_key @module_key else @module_key = begin if self.class.anchorless? self.class.pattern_code.camelize elsif anchor_codenames codenames = [self.class.pattern_code] + anchor_codenames.map(&:to_s) codenames.map(&:camelize).join "::" end end end end |
#module_list ⇒ Object
117 118 119 |
# File 'lib/card/set_pattern.rb', line 117 def module_list lookup_module_list Card::Set.modules[:nonbase] end |
#pattern ⇒ Object
148 149 150 |
# File 'lib/card/set_pattern.rb', line 148 def pattern @pattern ||= self.class.pattern end |
#rule_set_key ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/card/set_pattern.rb', line 169 def rule_set_key if self.class.anchorless? self.class.pattern_code elsif @anchor_id "#{@anchor_id}+#{self.class.pattern_code}" end end |
#safe_key ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'lib/card/set_pattern.rb', line 160 def safe_key caps_part = self.class.pattern_code.tr(" ", "_").upcase if self.class.anchorless? caps_part else "#{caps_part}-#{@anchor_name.safe_key}" end end |
#to_s ⇒ Object
152 153 154 |
# File 'lib/card/set_pattern.rb', line 152 def to_s self.class.anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}" end |