tabletop-companion/app/models/stat.rb

30 lines
698 B
Ruby
Raw Normal View History

2024-06-07 14:38:10 +00:00
# frozen_string_literal: true
class Stat < ApplicationRecord
2024-06-12 15:13:07 +00:00
include Sluggable
2024-06-07 14:38:10 +00:00
belongs_to :character_sheet_section
validates :name, presence: true,
length: { maximum: 100 },
uniqueness: { scope: :character_sheet_section_id }
validates :slug, presence: true,
length: { maximum: 100 },
uniqueness: true
validates :value, presence: true,
numericality: true
2024-06-11 13:55:39 +00:00
validate :validate_roll_command
2024-06-07 14:38:10 +00:00
2024-06-11 13:55:39 +00:00
def roll
DiceRoller.new(roll_command, stat: self).roll
end
2024-06-07 14:38:10 +00:00
private
2024-06-11 13:55:39 +00:00
def validate_roll_command
return if roll_command.blank?
DiceRoller.new(roll_command).valid?
end
2024-06-07 14:38:10 +00:00
end