Introduce architettura multi-sport con catalogo, engine scoring e overlay.
Catalogo sport in YAML, board implicito, engine per volley/basket/timed/racket/timer/generic, regia e app Android allineate. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
38
backend/app/domain/sports/rules_schema.rb
Normal file
38
backend/app/domain/sports/rules_schema.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Sports
|
||||
class RulesSchema
|
||||
INTEGER_RULES = {
|
||||
"volley" => %w[sets_to_win points_per_set points_deciding_set min_point_lead],
|
||||
"racket" => %w[sets_to_win points_per_set points_deciding_set min_point_lead],
|
||||
"basket" => %w[periods period_duration_secs overtime_duration_secs],
|
||||
"timed" => %w[periods period_duration_secs overtime_duration_secs],
|
||||
"timer" => [],
|
||||
"generic" => []
|
||||
}.freeze
|
||||
|
||||
def self.validate!(board_type, rules)
|
||||
board = board_type.to_s
|
||||
return if board == "generic" || board == "timer"
|
||||
|
||||
hash = rules.is_a?(Hash) ? rules : {}
|
||||
INTEGER_RULES.fetch(board, []).each do |key|
|
||||
val = hash[key] || hash[key.to_sym]
|
||||
next if val.blank?
|
||||
|
||||
unless val.is_a?(Integer) || val.to_s.match?(/\A\d+\z/)
|
||||
raise ArgumentError, "#{key} non valido"
|
||||
end
|
||||
int_val = val.to_i
|
||||
raise ArgumentError, "#{key} deve essere positivo" if int_val < 1
|
||||
end
|
||||
end
|
||||
|
||||
def self.validate(board_type, rules)
|
||||
validate!(board_type, rules)
|
||||
true
|
||||
rescue ArgumentError
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user