Module: JLPT::Reporter

Defined in:
lib/jlpt/formatters/reporter.rb

Overview

Interactive Visual Reporter.

Generates self-contained HTML reports with modern glassmorphism UI, difficulty level badges, progress bars, and GitHub-Flavored Markdown summaries.

Class Method Summary collapse

Class Method Details

.render_html(result) ⇒ String

Render a beautiful, standalone HTML report for an AnalysisResult

Parameters:

Returns:

  • (String)

    HTML string



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jlpt/formatters/reporter.rb', line 15

def render_html(result)
  furigana = Furigana.render(result.text, format: :html)
  lvl = result.recommended_level.to_s.upcase

  <<~HTML
    <!DOCTYPE html>
    <html lang="ja">
    <head><meta charset="UTF-8"><title>JLPT Analysis Report - #{lvl}</title>#{html_style_block}</head>
    <body>#{html_header_card(result)}<div class="card"><h2>Annotated Text</h2><div class="reading">#{furigana}</div></div></body>
    </html>
  HTML
end

.render_markdown(result) ⇒ String

Render a Markdown report table

Parameters:

Returns:

  • (String)

    Markdown string



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jlpt/formatters/reporter.rb', line 32

def render_markdown(result)
  <<~MARKDOWN
    # JLPT Analysis Report

    | Metric | Value |
    | :--- | :--- |
    | **Recommended Level** | #{result.recommended_level.to_s.upcase} |
    | **Difficulty Score** | #{result.score} / 100 |
    | **Kanji Density** | #{(result.kanji_density * 100).round(1)}% |
    | **Word Count** | #{result.word_count} |
    | **Sentence Count** | #{result.sentence_count} |
  MARKDOWN
end