class CwCardUtils::DecklistParser::Parser
Parses a decklist and returns a Deck object. Public: Parses a decklist string/IO into a Deck. 日本語: デッキリスト文字列/IOを解析して Deck を生成します。
Attributes
Public Class Methods
Source
# File lib/cw_card_utils/decklist_parser/parser.rb, line 17 def initialize(decklist, cmc_data_source = nil) @decklist = decklist.is_a?(IO) ? decklist.read : decklist @deck = Deck.new(cmc_data_source || CwCardUtils.card_data_source) end
Public: Create a new parser. 日本語: 新しいパーサを作成します。
@param decklist [String, IO] @param cmc_data_source [CwCardUtils::CardDataSource] @return [void]
Public Instance Methods
Source
# File lib/cw_card_utils/decklist_parser/parser.rb, line 26 def inspect "<DecklistParser::Parser: #{@decklist.length}>" end
Public: Human-readable summary. 日本語: 人間が読みやすい概要。
@return [String]
Source
# File lib/cw_card_utils/decklist_parser/parser.rb, line 45 def parse return @deck if @deck.any? sideboard = false @decklist.each_line do |line| line = line.strip next if line.empty? sideboard = true if line.downcase.start_with?("sideboard") && (sideboard == false) if line.match?(/^(Deck|Sideboard|About|Commander|Creatures|Lands|Spells|Artifacts|Enchantments|Planeswalkers|Mainboard|Maybeboard|Companion)/i) next end next if line.start_with?("#") # skip comment-style lines next if line.start_with?("//") # skip comment-style lines next if line.start_with?("Name") # skip deck name # Match patterns like: "4 Lightning Bolt", "2 Sol Ring (CMM) 452", "1 Atraxa, Praetors' Voice" next unless match = line.match(/^(\d+)\s+(.+?)(?:\s+\(.*?\)\s+\d+)?$/) # rubocop:disable Lint/AssignmentInCondition count = match[1].to_i name = match[2].strip target = sideboard ? :sideboard : :mainboard @deck.add({ count: count, name: name }, target) end @deck end
Parses the decklist and returns a Deck object. Public: Parse and return a Deck. Idempotent. 日本語: 解析して Deck を返します。多重実行に耐性があります。
How it works (EN): Streams the decklist line-by-line, skipping section headers and comments, toggling sideboard state as appropriate, and parsing counts/names using a permissive regex that tolerates set codes and collector numbers.
仕組み (JA): デッキリストを 1 行ずつ処理し、セクション見出しやコメントをスキップ、適宜サイドボード状態を切替えながら、枚数とカード名を寛容な正規表現で抽出します (セットコードやコレクタ番号を許容)。
@return [CwCardUtils::DecklistParser::Deck]