Sha256: 0b26a569ef8d9bda8a47e4aeb7a9b10ad1a5ce5ea5ebe9f586982ded3d8802ac

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

class Card
  module Set
    class Type < Pattern::Base
      cattr_accessor :assignment
      self.assignment = {}

      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 (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
        card.rule_card(:default, skip_modules: true)&.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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
card-1.104.2 lib/card/set/type.rb
card-1.104.1 lib/card/set/type.rb
card-1.104.0 lib/card/set/type.rb