class Card module Set class Pattern class << self def find pattern_code Card.set_patterns.find { |sub| sub.pattern_code == pattern_code } end def card_keys @card_keys ||= Card.set_patterns.inject({}) do |hash, set_pattern| card_key = Card.quick_fetch(set_pattern.pattern_code.to_sym).key hash[card_key] = true hash end end def write_tmp_file pattern_code, from_file, seq to_file = "#{Card.paths['tmp/set_pattern'].first}/" \ "#{seq}-#{pattern_code}.rb" klass = "Card::Set::#{pattern_code.camelize}" file_content = <" end 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 def rule_set_key if self.class.anchorless? self.class.pattern_code elsif @anchor_id "#{@anchor_id}+#{self.class.pattern_code}" end end end end class Type < Pattern::Abstract def initialize card super # support type inheritance @inherit_card = card unless module_key end def lookup_module_list modules_hash lookup_key = module_key || inherited_key modules_hash[lookup_key] if lookup_key end private def inherited_key if defined?(@inherited_key) @inherited_key else @inherited_key = lookup_inherited_key end end def lookup_inherited_key return unless @inherit_card card = @inherit_card @inherit_card = nil return unless (type_code = default_type_code card) mod_key = "Type::#{type_code.to_s.camelize}" mod_key if mods_exist_for_key? mod_key end def default_type_code card default_rule = card.rule_card :default default_rule && default_rule.type_code end def mods_exist_for_key? mod_key list_of_hashes = Card::Set.modules[:nonbase_format].values list_of_hashes << Card::Set.modules[:nonbase] list_of_hashes.any? { |h| h[mod_key] } end end end end