Sha256: a00a085fb44c83d22c78aecf564ae40d91b8341cc08f69d8b288613252acd002

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# Score Item 是评分项。
# #template 是评分项模版。
# #scorer 是评分者。
# #score_keeper 是得分者。

class Unidom::Score::ScoreItem < Unidom::Score::ApplicationRecord

  self.table_name = 'unidom_score_items'

  include Unidom::Common::Concerns::ModelExtension

  validates :title, allow_blank: true, length: { in: 2..columns_hash['title'].limit }
  validates :score, presence:    true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }

  belongs_to :sheet,    class_name:  'Unidom::Score::ScoreSheet',        foreign_key: :score_sheet_id
  belongs_to :template, class_name:  'Unidom::Score::ScoreItemTemplate', foreign_key: :score_item_template_id
  belongs_to :scorer,   polymorphic: true

  scope :sheet_is,    ->(sheet)    { where sheet:       sheet           }
  scope :template_is, ->(template) { where template_id: to_id(template) }
  scope :scored_by,   ->(scorer)   { where scorer:      scorer          }

  def self.score!(sheet: nil, scorer: nil, template: nil, name: template.try(:name), score: 0, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil)
    create! sheet: sheet, scorer: scorer, template: template, name: name, score: score, scored_on: scored_on, opened_at: opened_at, description: description, instruction: instruction
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-score-0.2 app/models/unidom/score/score_item.rb