Implemented category and priority setters in libpit. Started writing unit tests.

This commit is contained in:
Jonathan Bernard
2010-02-16 09:15:33 -06:00
parent c103591941
commit cfed10c3ed
12 changed files with 104 additions and 5 deletions

View File

@ -2,17 +2,20 @@ package com.jdbernard.pit
public class Issue {
String id
final String id
Category category
int priority
String title
String text
File source
Issue(File file) {
def matcher = file.name =~ /(\d{4})([bftc])(\d).*/
if (!matcher) return null
this.source = file
id = matcher[0][1]
category = Category.toCategory(matcher[0][2])
priority = matcher[0][3].toInteger()
@ -21,4 +24,18 @@ public class Issue {
text = file.text
}
void setCategory(Category c) {
this.category = c
source.renameTo(getFilename())
}
void setPriority(int p) {
if (p < 0) priority = 0
else if (p > 9) priority = 9
else priority = p
source.renameTo(getFilename())
}
String getFilename() { return id + category.symbol + priority + ".rst"; }
}

View File

@ -5,8 +5,14 @@ class Project {
String name
Map<String, Issue> issues = [:]
Map<String, Project> projects = [:]
File source
Project(File dir, Filter filter = null) {
if (!dir.isDirectory())
throw new IllegalArgumentException(
"${dir.name} is not a directory.")
this.source = dir
this.name = dir.name
dir.eachFile { child ->
@ -31,6 +37,8 @@ class Project {
}
}
}
public void rename(String newName) { source.renameTo(newName) }
public void eachIssue(Closure c) {
for (i in issues.values()) c.call(i)