48 lines
1.5 KiB
Ruby
48 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
repo = ClashDeckGenerator2::Repos::CardsRepo.new
|
||
|
||
CARD_TYPES = %w[troop spell building].freeze
|
||
RARITIES = %w[common rare epic legendary champion hero evolution].freeze
|
||
|
||
# Подключаем файлы с картами
|
||
require_relative "seeds/common"
|
||
require_relative "seeds/rare"
|
||
require_relative "seeds/epic"
|
||
require_relative "seeds/legendary"
|
||
require_relative "seeds/champion"
|
||
require_relative "seeds/hero"
|
||
require_relative "seeds/evo"
|
||
|
||
# Объединяем все карты
|
||
CARDS = []
|
||
CARDS.concat(COMMON_CARDS)
|
||
CARDS.concat(RARE_CARDS)
|
||
CARDS.concat(EPIC_CARDS)
|
||
CARDS.concat(LEGENDARY_CARDS)
|
||
CARDS.concat(CHAMPION_CARDS)
|
||
CARDS.concat(HERO_CARDS)
|
||
CARDS.concat(EVOLUTION_CARDS)
|
||
|
||
|
||
# ВАЛИДАЦИЯ
|
||
CARDS.each do |c|
|
||
raise "Missing name" if c[:name].nil? || c[:name].strip.empty?
|
||
raise "Missing elixir_cost for #{c[:name]}" if c[:elixir_cost].nil?
|
||
raise "Missing rarity for #{c[:name]}" if c[:rarity].nil?
|
||
raise "Missing type for #{c[:name]}" if c[:type].nil?
|
||
|
||
raise "Unknown rarity: #{c[:rarity]} for #{c[:name]}" unless RARITIES.include?(c[:rarity])
|
||
raise "Unknown type: #{c[:type]} for #{c[:name]}" unless CARD_TYPES.include?(c[:type])
|
||
end
|
||
|
||
# Проверка на дубликаты
|
||
names = CARDS.map { |c| c[:name] }
|
||
duplicates = names.group_by { |name| name }.select { |_k, v| v.size > 1 }.keys
|
||
raise "Duplicate cards found: #{duplicates.join(', ')}" if duplicates.any?
|
||
|
||
|
||
# ЗАПИСЬ В БАЗУ
|
||
CARDS.each do |card|
|
||
repo.create(card)
|
||
end |