-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkdownFormatter.java
More file actions
100 lines (83 loc) · 3.73 KB
/
MarkdownFormatter.java
File metadata and controls
100 lines (83 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.preponderous.parpt.export;
import com.preponderous.parpt.domain.Project;
import com.preponderous.parpt.score.ScoreCalculator;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* Component responsible for formatting project data into markdown strings.
* This class handles the actual markdown formatting logic without dealing with file I/O.
*/
@Component
public class MarkdownFormatter {
private final ScoreCalculator scoreCalculator;
private final ScoreDescriptionProvider scoreDescriptionProvider;
public MarkdownFormatter(ScoreCalculator scoreCalculator, ScoreDescriptionProvider scoreDescriptionProvider) {
this.scoreCalculator = scoreCalculator;
this.scoreDescriptionProvider = scoreDescriptionProvider;
}
/**
* Generates the markdown header with timestamp and sorting information.
*
* @param sortByRice true if sorted by RICE, false if sorted by ICE
* @return formatted header string
*/
public String formatHeader(boolean sortByRice) {
StringBuilder header = new StringBuilder();
header.append("# Project Priorities\n\n");
header.append("*Generated on ")
.append(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
.append("*\n\n");
String scoreType = sortByRice ? "RICE" : "ICE";
header.append("*Sorted by ").append(scoreType).append(" score (highest to lowest)*\n\n");
return header.toString();
}
/**
* Formats a single project into markdown.
*
* @param project the project to format
* @param rank the ranking position (1, 2, 3, etc.)
* @return formatted project markdown string
*/
public String formatProject(Project project, int rank) {
StringBuilder content = new StringBuilder();
double iceScore = scoreCalculator.ice(project);
double riceScore = scoreCalculator.rice(project);
// Project header and description
content.append("## ").append(rank).append(". ").append(project.getName()).append("\n\n");
content.append("**Description:** ").append(project.getDescription()).append("\n\n");
// Scores summary
content.append("### Scores\n");
content.append("- **ICE Score:** ").append(String.format("%.2f", iceScore)).append("\n");
content.append("- **RICE Score:** ").append(String.format("%.2f", riceScore)).append("\n\n");
// Individual components
content.append("### Components\n");
content.append(formatScoreComponent("Impact", project.getImpact()));
content.append(formatScoreComponent("Confidence", project.getConfidence()));
content.append(formatScoreComponent("Ease", project.getEase()));
content.append(formatScoreComponent("Reach", project.getReach()));
content.append(formatScoreComponent("Effort", project.getEffort()));
content.append("\n");
content.append("---\n\n");
return content.toString();
}
/**
* Formats a single score component line.
*
* @param componentName the name of the component (Impact, Confidence, etc.)
* @param score the numerical score (1-5)
* @return formatted component line
*/
private String formatScoreComponent(String componentName, int score) {
return "- **" + componentName + ":** " + score + "/5 (" +
scoreDescriptionProvider.getDescription(score) + ")\n";
}
/**
* Formats the "no projects found" message.
*
* @return formatted no projects message
*/
public String formatNoProjectsMessage() {
return "No projects found.\n";
}
}