tabletop-companion/app/models/stat.rb

30 lines
698 B
Ruby

# frozen_string_literal: true
class Stat < ApplicationRecord
include Sluggable
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
validate :validate_roll_command
def roll
DiceRoller.new(roll_command, stat: self).roll
end
private
def validate_roll_command
return if roll_command.blank?
DiceRoller.new(roll_command).valid?
end
end