Sha256: 8181d6423c9bf8e58d1f582aea052e819e6bfdcca9ea217786a3348154064fa4

Contents?: true

Size: 1.09 KB

Versions: 14

Compression:

Stored size: 1.09 KB

Contents

class Card
  module Set
    class Type < Pattern::Base
      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)&.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

14 entries across 14 versions & 1 rubygems

Version Path
card-1.102.0 lib/card/set/type.rb
card-1.101.6 lib/card/set/type.rb
card-1.101.5 lib/card/set/type.rb
card-1.101.4 lib/card/set/type.rb
card-1.101.3 lib/card/set/type.rb
card-1.101.2 lib/card/set/type.rb
card-1.101.1 lib/card/set/type.rb
card-1.101.0 lib/card/set/type.rb
card-1.100.0 lib/card/set/type.rb
card-1.99.6 lib/card/set/type.rb
card-1.99.5 lib/card/set/type.rb
card-1.99.4 lib/card/set/type.rb
card-1.99.3 lib/card/set/type.rb
card-1.99.2 lib/card/set/type.rb