lib/cw_card_utils/decklist_parser/card.rb
# frozen_string_literal: true module CwCardUtils module DecklistParser # A Card is a single card in a deck. class Card def initialize(name, count, cmc_data_source = nil) @name = name @count = count @tags = [] @cmc_data_source = cmc_data_source || CwCardUtils.card_data_source end attr_reader :name, :count, :cmc_data_source attr_accessor :tags def cmc @cmc ||= @cmc_data_source&.cmc_for_card(@name) end def type @type ||= @cmc_data_source&.type_for_card(@name) || "Land" end def keywords @keywords ||= @cmc_data_source&.keywords_for_card(@name) || [] end def oracle_text @oracle_text ||= @cmc_data_source&.oracle_text_for_card(@name) end def power @power ||= @cmc_data_source&.power_for_card(@name) end def toughness @toughness ||= @cmc_data_source&.toughness_for_card(@name) end def color_identity @color_identity ||= @cmc_data_source&.color_identity_for_card(@name) || [] end def inspect "<Card: #{@name} (#{@count}) #{cmc}>" end def to_h { name: @name, count: @count, cmc: cmc, type: type, keywords: keywords, power: power, toughness: toughness, oracle_text: oracle_text } end def to_json(*_args) to_h.to_json end end end end