timestamper/src/main/com/jdbernard/timeanalyzer/TwoLevelCategorizationPlan.groovy

22 lines
701 B
Groovy
Raw Normal View History

package com.jdbernard.timeanalyzer
public class TwoLevelCategorizationPlan implements CategorizationPlan {
private static final def TWO_LEVEL_PATTERN = ~/(.+?):(.*)/
public boolean deservesNewCategory(Event event, List<Entry> el) {
return event ==~ TWO_LEVEL_PATTERN
}
public Category newCategory(Event event, List<Entry> el) {
def m = event.description =~ TWO_LEVEL_PATTERN
return new TwoLevelCategory(m[0][1])
}
public List<Entry> findEntriesToRecategorize(Event event,
List<Entry> existingEntries) {
def m = event.description =~ TWO_LEVEL_PATTERN
return existingEntries.findAll { it.description ==~ /${m[0][1]}:.*/ }
}
}