31 lines
918 B
Groovy
31 lines
918 B
Groovy
|
package com.quantumdigital.ithelp.timeanalyzer
|
||
|
|
||
|
import com.jdbernard.timeanalyzer.Category
|
||
|
import com.jdbernard.timeanalyzer.CategorizationPlan
|
||
|
import com.jdbernard.timeanalyzer.Event
|
||
|
import com.jdbernard.timeanalyzer.Entry
|
||
|
|
||
|
public class TicketCategorizationPlan implements CategorizationPlan {
|
||
|
|
||
|
private static def TICKET_PATTERN = ~/.*#(\d+).*/
|
||
|
|
||
|
public boolean deservesNewCategory(Event e, List<Entry> el) {
|
||
|
return e.description ==~ TICKET_PATTERN
|
||
|
}
|
||
|
|
||
|
public Category newCategory(Event e, List<Entry> el) {
|
||
|
def m = e.description =~ TICKET_PATTERN
|
||
|
|
||
|
return new TicketCategory(m[0][1] as int)
|
||
|
}
|
||
|
|
||
|
public List<Entry> findEntriesToRecategorize(Event e,
|
||
|
List<Entry> existingEntries) {
|
||
|
def m = e.description =~ TICKET_PATTERN
|
||
|
int ticketId = m[0][1] as int
|
||
|
|
||
|
return existingEntries.findAll {
|
||
|
it.description ==~ /.*#${ticketId}.*/ }
|
||
|
}
|
||
|
}
|