Class: CompletionKit::Metric
Constant Summary
collapse
- DEFAULT_RUBRIC_BANDS =
[
{ "stars" => 5, "description" => "Fully meets or exceeds all criteria. No meaningful issues." },
{ "stars" => 4, "description" => "Meets criteria well. Minor issues only." },
{ "stars" => 3, "description" => "Meets criteria adequately. Some room for improvement." },
{ "stars" => 2, "description" => "Partially meets criteria. Significant gaps or frequent errors." },
{ "stars" => 1, "description" => "Fails to meet the criteria. Major errors or completely off-target." }
].freeze
ApplicationRecord::TenantScopedUniquenessValidator
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.default_rubric_bands ⇒ Object
24
25
26
|
# File 'app/models/completion_kit/metric.rb', line 24
def self.default_rubric_bands
DEFAULT_RUBRIC_BANDS.map(&:dup)
end
|
.default_rubric_text ⇒ Object
28
29
30
|
# File 'app/models/completion_kit/metric.rb', line 28
def self.default_rubric_text
rubric_text_for(default_rubric_bands)
end
|
.normalize_rubric_bands(raw_bands) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/models/completion_kit/metric.rb', line 40
def self.normalize_rubric_bands(raw_bands)
bands = raw_bands.is_a?(Hash) ? raw_bands.values : Array(raw_bands)
band_map = bands.each_with_object({}) do |band, acc|
next unless band.respond_to?(:to_h)
normalized = band.to_h.stringify_keys.slice("stars", "description")
stars = normalized["stars"].to_i
next unless (1..5).cover?(stars)
acc[stars] = {
"stars" => stars,
"description" => normalized["description"].to_s.strip
}
end
default_rubric_bands.map do |default_band|
stars = default_band["stars"]
band = band_map[stars]
{
"stars" => stars,
"description" => band && band["description"].present? ? band["description"] : default_band["description"]
}
end
end
|
.rubric_text_for(bands) ⇒ Object
32
33
34
35
36
37
38
|
# File 'app/models/completion_kit/metric.rb', line 32
def self.rubric_text_for(bands)
Array(bands).sort_by { |b| -(b["stars"] || 0) }.map do |band|
stars = band["stars"].to_i
label = stars == 1 ? "1 star" : "#{stars} stars"
"#{label}: #{band["description"]}"
end.join("\n\n")
end
|
Instance Method Details
#as_json(options = {}) ⇒ Object
73
74
75
76
77
78
79
|
# File 'app/models/completion_kit/metric.rb', line 73
def as_json(options = {})
{
id: id, name: name, key: key, instruction: instruction,
rubric_bands: rubric_bands,
created_at: created_at, updated_at: updated_at
}
end
|
#display_rubric_text ⇒ Object
69
70
71
|
# File 'app/models/completion_kit/metric.rb', line 69
def display_rubric_text
self.class.rubric_text_for(rubric_bands_for_form)
end
|
65
66
67
|
# File 'app/models/completion_kit/metric.rb', line 65
def rubric_bands_for_form
self.class.normalize_rubric_bands(rubric_bands)
end
|