1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 08:18:52 -05:00

* simplify csv lookup and replacement of values based on csv mappings

This commit is contained in:
Reinhard Pointner 2013-06-25 02:40:19 +00:00
parent 62732521c5
commit 08cf9720e8

View File

@ -5,6 +5,7 @@ import java.util.regex.Pattern
// simplified switch/case pattern matching
Object.metaClass.match = { Map cases -> def val = delegate; cases.findResult { switch(val) { case it.key: return it.value} } }
def csv(path, delim = ';', keyIndex = 0, valueIndex = 1) { def f = path as File; def values = [:]; f.splitEachLine(delim) { values.put(it[keyIndex], it[valueIndex]) }; return values }
def c(c) { try { c.call() } catch (Throwable e) { null } }