Worlds Bets
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
sto
2026-09-06 10:07:47 +02:00
parent 49e49dc93d
commit dae86bd1ea
33 changed files with 1337 additions and 1 deletions

View File

@@ -0,0 +1,56 @@
# == Schema Information
#
# Table name: world_participants
#
# id :integer not null, primary key
# final_result :integer
# name :string not null
# qualifier_result :integer
# round :string not null
# score :integer
# semifinal_result :integer
# username :string not null
# created_at :datetime not null
# updated_at :datetime not null
# world_country_id :integer not null
#
# Indexes
#
# index_world_participants_on_world_country_id (world_country_id)
#
# Foreign Keys
#
# world_country_id (world_country_id => world_countries.id)
#
class WorldParticipant < ApplicationRecord
belongs_to :world_country
validates :name, presence: true
validates :username, presence: true
validates :round, inclusion: { in: %w[a b c d], message: "%{value} is not a valid round" }
validates :qualifier_result, numericality: { greater_than_or_equal_to: 1 }, if: -> { qualifier_result.present? }
validates :semifinal_result, numericality: { greater_than_or_equal_to: 1 }, if: -> { semifinal_result.present? }
validates :final_result, numericality: { greater_than_or_equal_to: 1 }, if: -> { final_result.present? }
before_save :compute_score
def compute_score
self.score = WorldBet.points(qualifier_result) + WorldBet.points(semifinal_result) * 2 + WorldBet.points(final_result) * 4
end
def self.add_participants(str)
str.split(";", -1).each do |c|
cs = c.split(",", -1)
if cs.length >= 4
name = cs.first
username = cs[1]
country_code = cs[2]
round = cs.last
country = WorldCountry.where(code: country_code).first
if country
WorldParticipant.create(name: name, username: username, world_country: country, round: round)
end
end
end
end
end