lib/card/set/pattern/base.rb in card-1.103.4 vs lib/card/set/pattern/base.rb in card-1.104.0

- old
+ new

@@ -1,21 +1,23 @@ class Card module Set - class Pattern + module Pattern # class from which set patterns inherit class Base extend ClassMethods + delegate :pattern_code, :pattern, :anchorless?, :anchor_parts_count, + :assigns_type, to: :class def initialize card - return if self.class.anchorless? + return if anchorless? @anchor_name = self.class.anchor_name(card).to_name @anchor_id = find_anchor_id card end def find_anchor_id card - self.class.try(:anchor_id, card) || Card.fetch_id(@anchor_name) + self.class.try(:anchor_id, card) || @anchor_name.card_id end def module_key return @module_key if defined? @module_key @@ -51,35 +53,27 @@ # 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 - def anchor_parts_count - self.class.anchor_parts_count - end - - def pattern - @pattern ||= self.class.pattern - end - def to_s - self.class.anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}" + anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}" end def inspect "<#{self.class} #{to_s.to_name.inspect}>" end def safe_key - caps_part = self.class.pattern_code.to_s.tr(" ", "_").upcase - self.class.anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}" + caps_part = pattern_code.to_s.tr(" ", "_").upcase + anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}" end - def rule_set_key - if self.class.anchorless? - self.class.pattern_code.to_s + def rule_lookup_key + if anchorless? + pattern_code.to_s elsif @anchor_id - "#{@anchor_id}+#{self.class.pattern_code}" + "#{@anchor_id}+#{pattern_code}" end end end end end