class CwCardUtils::DecklistParser::Parser
def parse
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