Commits

aeris committed 4fe7de5

Change review format

Comments (0)

Files changed (1)

src/main/java/fr/imirhil/april/hebdobot/review/Review.java

 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
 
 import fr.imirhil.april.hebdobot.xml.UserAlias;
 
 
 	public String toString(final UserAlias userService) {
 		final StringBuffer buffer = new StringBuffer();
-		addBox(buffer, "Revue de la semaine en cours", '#');
-		buffer.append("\n");
-
-		buffer.append("\n");
-		addBox(buffer, "Participants", '=');
-		buffer.append("\n");
+		addLine(buffer, '=');
+		addCenter(buffer, "Revue de la semaine en cours");
+		addEmpty(buffer);
+		addCenter(buffer, DateTimeFormat.fullDate().print(new DateTime()));
+		addLine(buffer, '=');
+		addEmpty(buffer);
+		addEmpty(buffer);
+
+		addLine(buffer, '=');
+		addEmpty(buffer);
+		addCenter(buffer, "Participants", '-');
 		for (final String participant : this.participants) {
-			chunkAndAppend(buffer, "* " + userService.getRealName(participant)
-					+ "\n");
+			addChunk(buffer, "* " + userService.getRealName(participant) + "\n");
 		}
-		buffer.append("\n");
 
 		if (!this.individualTopics.isEmpty()) {
-			buffer.append("\n");
-			addBox(buffer, "Sujets individuels", '=');
 			for (final String participant : this.participants) {
-				buffer.append("\n");
-				buffer.append(getLine(userService.getRealName(participant), '-'));
+				addEmpty(buffer);
+				addLine(buffer, '=');
+				addEmpty(buffer);
+				addCenter(buffer, userService.getRealName(participant), '-');
 				for (final IndividualTopic topic : this.individualTopics) {
 					if (topic.hasParticipant(participant)) {
-						buffer.append("\n");
-						chunkAndAppend(buffer, getTopic(topic));
-						buffer.append("\n");
+						addEmpty(buffer);
+						add(buffer, getTopic(topic));
+						addEmpty(buffer);
 						for (final Message message : topic
 								.getMessages(participant)) {
-							chunkAndAppend(buffer, "* " + message.getContent()
-									+ "\n");
+							addChunk(buffer, "* " + message.getContent() + "\n");
 						}
 					}
 				}
 			}
-			buffer.append("\n");
 		}
 
 		if (!this.collectiveTopics.isEmpty()) {
-			buffer.append("\n");
-			addBox(buffer, "Sujets collectifs", '=');
 			for (final CollectiveTopic topic : this.collectiveTopics) {
-				buffer.append("\n");
-				addBox(buffer, topic.getTitle(), '-');
+				addEmpty(buffer);
+				addLine(buffer, '=');
+				addCenter(buffer, topic.getTitle());
+				addLine(buffer, '=');
+				addEmpty(buffer);
 				for (final Message message : topic.getMessages()) {
-					chunkAndAppend(buffer, "* " + message.getAuthor() + " : "
+					addChunk(buffer, "* " + message.getAuthor() + " : "
 							+ message.getContent() + "\n");
 				}
 			}
-			buffer.append("\n");
 		}
 
-		buffer.append("\n");
-		addBox(buffer, "Log complet", '=');
-		buffer.append("\n");
+		addEmpty(buffer);
+		addCenter(buffer, "Log IRC brut");
+		addEmpty(buffer);
 		for (final Message message : this.messages) {
-			chunkAndAppend(buffer,
+			addChunk(buffer,
 					"* " + message.getAuthor() + " : " + message.getContent()
 							+ "\n");
 		}
 		return StringUtils.repeat(c.toString(), LENGTH) + "\n";
 	}
 
-	private static String getLine(final String content, final Character c) {
+	private static String getLine(final String content, final char c) {
 		return StringUtils.center(" " + content + " ", LENGTH, c) + "\n";
 	}
 
 	private static String getTopic(final Topic topic) {
-		return "===  " + topic.getTitle() + "  ===";
+		return "===  " + topic.getTitle() + "  ===\n";
 	}
 
-	private static void addBox(final StringBuffer buffer, final String title,
-			final Character c) {
-		buffer.append(getLine(c));
-		buffer.append(getLine(title, ' '));
+	private static void addCenter(final StringBuffer buffer,
+			final String content, final char c) {
+		buffer.append(getLine(content, c));
+	}
+
+	private static void addCenter(final StringBuffer buffer,
+			final String content) {
+		addCenter(buffer, content, ' ');
+	}
+
+	private static void addLine(final StringBuffer buffer, final char c) {
 		buffer.append(getLine(c));
 	}
 
+	private static void addEmpty(final StringBuffer buffer) {
+		buffer.append("\n");
+	}
+
 	private static String chunk(final String content, final int length) {
 		final String[] words = content.split(" ");
 		final StringBuffer result = new StringBuffer();
 		return result.toString();
 	}
 
+	private static void add(final StringBuffer buffer, final String content) {
+		buffer.append(content);
+	}
+
 	private static String chunk(final String content) {
 		return chunk(content, LENGTH);
 	}
 
-	private static void chunkAndAppend(final StringBuffer buffer,
-			final String content) {
-		buffer.append(chunk(content));
+	private static void
+			addChunk(final StringBuffer buffer, final String content) {
+		add(buffer, chunk(content));
 	}
+
 }