Class: RubyTestStudentGrader::ClassReporter
- Inherits:
-
Object
- Object
- RubyTestStudentGrader::ClassReporter
- Defined in:
- lib/ruby_test_student_grader/class_reporter.rb
Overview
Genera reportes para múltiples estudiantes y un índice HTML simple.
Instance Method Summary collapse
- #generate_all ⇒ Object
-
#initialize(students, **opts) ⇒ ClassReporter
constructor
students: Array
con claves: :id, :name, :total_score, :max_score, :failed_tests (Array), :feedback (String) opts: { course_name?: String, output_dir?: String }.
Constructor Details
#initialize(students, **opts) ⇒ ClassReporter
students: Array
:id, :name, :total_score, :max_score, :failed_tests (Array), :feedback (String)
opts: { course_name?: String, output_dir?: String }
9 10 11 12 13 |
# File 'lib/ruby_test_student_grader/class_reporter.rb', line 9 def initialize(students, **opts) @students = students @course_name = opts[:course_name] || ENV["COURSE_NAME"] || "Curso" @output_dir = opts[:output_dir] || "reports" end |
Instance Method Details
#generate_all ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby_test_student_grader/class_reporter.rb', line 15 def generate_all Dir.mkdir(@output_dir) unless Dir.exist?(@output_dir) index_rows = [] @students.each do |s| base = safe_slug("#{s[:id]}-#{s[:name]}") html_path = File.join(@output_dir, "#{base}.html") csv_path = File.join(@output_dir, "#{base}.csv") reporter = Reporter.new( s[:total_score], s[:max_score], s[:failed_tests] || [], s[:feedback].to_s, course_name: @course_name ) reporter.generate_html(html_path) reporter.generate_csv(csv_path) percentage = s[:max_score].to_f.zero? ? 0.0 : (s[:total_score].to_f / s[:max_score] * 100) index_rows << { id: s[:id], name: s[:name], html: File.basename(html_path), csv: File.basename(csv_path), percentage: percentage.round(2) } end index_file = File.join(@output_dir, "index.html") File.write(index_file, render_index(index_rows)) puts "✅ Class index generated at: #{index_file}" index_file end |