class CwCardUtils::DecklistParser::Deck
Public: A deck is a collection of cards and utilities around it. 日本語: デッキはカードの集合であり、各種ユーティリティを提供します。
Constants
- IGNORED_TRIBAL_TYPES
Public Class Methods
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 17 def initialize(cmc_data_source) @main = [] @sideboard = [] @lands = [] @x_to_cast = [] @cmc_data_source = cmc_data_source end
Public: Initialize an empty deck with a data source. 日本語: データソースを指定して空のデッキを初期化します。
@param cmc_data_source [CwCardUtils::CardDataSource] @return [void]
Public Instance Methods
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 211 def add(c, target = :mainboard) reset_counters card = Card.new(c[:name], c[:count], @cmc_data_source) card.tags = CwCardUtils::DecklistParser::CardTagger.new(card, self).tags if target == :mainboard @main << card else @sideboard << card end if card.type.include?("Land") @lands << card elsif card.cmc.nil? @x_to_cast << card end end
Public: Add a card hash to mainboard or sideboard. 日本語: カードをメイン/サイドに追加します。
@param c [Hash] { name:, count: } @param target [Symbol] :mainboard or :sideboard @return [void]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 190 def any? !empty? end
Public: True when deck has any cards. 日本語: 1枚でもカードがあれば true。
@return [Boolean]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 110 def archetype @archetype ||= CwCardUtils::DecklistParser::ArchetypeDetector.new(self).detect end
Public: Detected archetype label. 日本語: 検出されたアーキタイプのラベル。
Intent (EN): Summarize the deck’s strategic identity using aggregated tag ratios/counts and average CMC.
意図 (JA): タグの比率/件数と平均 CMC を用いて、デッキの戦略的アイデンティティを要約します。
@return [String]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 333 def cards_count mainboard_size + sideboard_size end
Public: Total main+sideboard count. 日本語: メイン+サイドの合計枚数。
@return [Integer]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 132 def collapsed_curve @collapsed_curve ||= CurveCalculator.new(self).collapsed_curve end
Public: Collapsed curve counts. 日本語: まとめられたカーブのカウント。
Intent (EN): Provide a coarse view of the deck’s curve using canonical buckets for quick comparison.
意図 (JA): 代表的なバケットでカーブを粗く表し、比較を容易にします。
@return [Hash{String=>Integer}]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 174 def collapsed_normalized_curve @collapsed_normalized_curve ||= CurveCalculator.new(self).collapsed_normalized_curve end
Public: Collapsed normalized curve. 日本語: まとめられかつ正規化されたカーブ。
Intent (EN): Normalize the collapsed buckets for concise and comparable summaries.
意図 (JA): まとめたバケットを正規化し、簡潔かつ比較しやすい要約を提供します。
@return [Hash{String=>Float}]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 42 def color_identity @color_identity ||= main.map(&:color_identity).flatten.uniq end
Public: Unique color identity across mainboard. 日本語: メインボードの色アイデンティティ集合。
@return [Array<String>]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 50 def color_identity_string @color_identity_string ||= CwCardUtils::DecklistParser::ColorIdentityResolver.resolve(color_identity) end
Public: Human readable color label. 日本語: 人間が読みやすい色表記。
@return [String]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 341 def count_without_lands cards_count - lands_count end
Public: Total non-land count. 日本語: 土地以外の総枚数。
@return [Integer]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 146 def curve @curve ||= CurveCalculator.new(self).curve end
Public: Raw curve counts. 日本語: 素のカーブカウント。
Intent (EN): Exact histogram of non-land CMC ceilings used by calculators and visualizations.
意図 (JA): 計算や可視化で用いる、土地以外の CMC 切り上げのヒストグラムです。
@return [Hash{Integer=>Integer}]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 259 def detect_format_for_deck if mainboard_size >= 100 :commander elsif mainboard_size >= 60 # Check if this looks like Commander (60+ cards, singleton except for basic lands) if mainboard_size >= 60 && is_singleton_deck? :commander else :standard end else :modern end end
Public: Detect the format from deck size and singleton rules. 日本語: デッキサイズとシングルトン規則からフォーマットを判定します。
How it works (EN): Uses size thresholds (>=100 => Commander), then checks for singleton behavior ignoring basic lands to disambiguate Commander-like 60+ lists from Standard.
仕組み (JA): サイズ閾値 (>=100 は Commander) を用い、基本土地を無視したシングルトン性を確認して、Standard と似た 60+ のCommander らしさを判別します。
@return [Symbol]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 366 def detect_tribe_for_deck subtype_counts = Hash.new(0) total_creatures = 0 @main.each do |card| next unless card.type&.include?("Creature") total_creatures += 1 subtypes = card.type.split(/[—-]/).last.to_s.strip.split subtypes.each do |type| subtype_counts[type.downcase] += 1 end end return nil if total_creatures < 6 || subtype_counts.empty? most_common = subtype_counts.max_by { |_, count| count } return nil if most_common.nil? dominant_type = most_common[0] count = most_common[1] # Suppress only if it's a boring type *and* barely dominant if IGNORED_TRIBAL_TYPES.include?(dominant_type) && count.to_f / total_creatures < 0.7 return nil end return dominant_type.to_sym if count.to_f / total_creatures >= 0.4 nil end
Public: Detect dominant creature subtype if present. 日本語: 優勢なクリーチャー・サブタイプがあれば検出します。
@return [Symbol, nil]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 199 def each(&block) @main.each do |c| block.call(c) end end
Public: Enumerate mainboard cards. 日本語: メインボードのカードを列挙します。
@yield [CwCardUtils::DecklistParser::Card] カードをブロックに渡します@return [void]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 182 def empty? @main.empty? && @sideboard.empty? end
Public: True when both main and sideboard are empty. 日本語: メイン・サイドの両方が空であれば true。
@return [Boolean]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 243 def format @format ||= detect_format_for_deck end
Public: Detected format (:commander, :standard, :modern)。日本語: 判定されたフォーマット (:commander, :standard, :modern)。
@return [Symbol]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 118 def inspect "<Deck: main: #{mainboard_size} sideboard: #{sideboard_size} lands: #{lands_count} x_to_cast: #{x_to_cast_count} cards: #{cards_count}>" end
Public: Human-friendly deck summary string. 日本語: 人が読みやすいデッキ概要文字列。
@return [String]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 292 def is_basic_land?(card) basic_land_names = %w[Plains Island Swamp Mountain Forest Wastes] basic_land_names.include?(card.name) end
Internal: Whether a card is a basic land. 日本語: 基本土地であるかどうか。
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 276 def is_singleton_deck? # Count non-basic land cards and check for duplicates non_basic_lands = @main.reject { |card| is_basic_land?(card) } # Check if any non-basic land card appears more than once card_counts = Hash.new(0) non_basic_lands.each do |card| card_counts[card.name] += card.count end # All non-basic land cards should appear only once card_counts.values.all? { |count| count == 1 } end
Internal: Whether the deck is singleton ignoring basic lands. 日本語: 基本土地を無視してシングルトンかどうか。
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 317 def lands_count @lands.sum { |card| card.count } end
Public: Land count. 日本語: 土地の枚数。
@return [Integer]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 73 def main tag_cards(@main) end
Public: Mainboard cards with tags applied. 日本語: タグ適用済みのメインボードカード一覧。
How it works (EN): Lazily computes tags for each card via ‘CardTagger` the first time access occurs, then returns the mutated card objects for downstream consumers.
仕組み (JA): 初回アクセス時に ‘CardTagger` で各カードのタグを遅延計算し、以降はタグ付け済みカードを返します。
@return [Array<CwCardUtils::DecklistParser::Card>]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 301 def mainboard_size @mainboard_size ||= main.sum { |card| card.count } end
Public: Total mainboard card count. 日本語: メインボードの総枚数。
@return [Integer]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 160 def normalized_curve @normalized_curve ||= CurveCalculator.new(self).normalized_curve end
Public: Normalized curve fractions. 日本語: 正規化されたカーブ比率。
Intent (EN): Convert raw counts into proportions of non-land cards to compare decks of different sizes.
意図 (JA): デッキサイズが異なる場合でも比較できるよう、土地以外の枚数で割った比率に変換します。
@return [Hash{Integer=>Float}]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 231 def reset_counters @mainboard_size = nil @sideboard_size = nil @lands_count = nil @x_to_cast_count = nil @cards_count = nil end
Internal: Invalidate derived counters. 日本語: 派生カウンタを無効化します。
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 87 def sideboard tag_cards(@sideboard) end
Public: Sideboard cards with tags applied. 日本語: タグ適用済みのサイドボードカード一覧。
How it works (EN): Same lazy-tagging behavior as ‘main`, but for sideboard entries.
仕組み (JA): ‘main` と同様に遅延タグ付けを行いますが、対象はサイドボードです。
@return [Array<CwCardUtils::DecklistParser::Card>]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 309 def sideboard_size @sideboard_size ||= sideboard.sum { |card| card.count } end
Public: Total sideboard card count. 日本語: サイドボードの総枚数。
@return [Integer]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 349 def size cards_count end
Public: Deck size including sideboard. 日本語: サイドボードを含むデッキサイズ。
@return [Integer]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 93 def tag_cards(cards) cards.map do |c| c.tags = CwCardUtils::DecklistParser::CardTagger.new(c, self).tags c end end
Internal: Apply tags to cards lazily. 日本語: 遅延的にカードへタグを適用します。
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 30 def to_h { mainboard: main.map(&:to_h), sideboard: sideboard.map(&:to_h), tribe: tribe, } end
Public: Serialize as a Hash suitable for JSON. 日本語: JSON化に適したHashへシリアライズします。
@return [Hash]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 58 def to_json(*_args) to_h.to_json end
Public: JSON representation of the deck. 日本語: デッキのJSON表現。
@return [String]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 357 def tribe return @tribe if @tribe @tribe = detect_tribe_for_deck end
Public: Dominant tribe symbol or nil. 日本語: 優勢な部族(トライブ)のシンボル、もしくは nil。
@return [Symbol, nil]
Source
# File lib/cw_card_utils/decklist_parser/deck.rb, line 325 def x_to_cast_count @x_to_cast.sum { |card| card.count } end
Public: X-to-cast count. 日本語: Xコストのカード枚数。
@return [Integer]