aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiederick de Vries <diederick@diederickdevries.net>2018-11-19 13:49:56 +0100
committerDiederick de Vries <diederick@diederickdevries.net>2018-11-19 13:49:56 +0100
commitb1fb06f72d4fffdd22f9adea5c9487ff0d5255b4 (patch)
tree6b5d86a4d6a6e6380a6631a1191e5049272ee500
parent1da3a53baab4c336ba386c546c147ac3b6843e44 (diff)
downloadaftercare-b1fb06f72d4fffdd22f9adea5c9487ff0d5255b4.tar.gz
aftercare-b1fb06f72d4fffdd22f9adea5c9487ff0d5255b4.tar.bz2
aftercare-b1fb06f72d4fffdd22f9adea5c9487ff0d5255b4.zip
fix: make findEpisodeName() more robust
-rw-r--r--aftercare.groovy22
1 files changed, 7 insertions, 15 deletions
diff --git a/aftercare.groovy b/aftercare.groovy
index af8870e..697d71d 100644
--- a/aftercare.groovy
+++ b/aftercare.groovy
@@ -136,29 +136,21 @@ class Aftercare {
136 } 136 }
137 log.info "finished" 137 log.info "finished"
138 } 138 }
139
140 private String capitalize(String s) {
141 def c = [], t = ""
142
143 s.tokenize(' ').each { word ->
144 c << word.capitalize()
145 }
146
147 c.each { word ->
148 t = t + " " + word
149 }
150 return t.trim()
151 }
152 139
153 private String findEpisodeNumber(String s) { 140 private String findEpisodeNumber(String s) {
154 return s.toLowerCase().startsWith('s') ? s.substring(1,3) : s.substring(0,2) 141 return s.toLowerCase().startsWith('s') ? s.substring(1,3) : s.substring(0,2)
155 } 142 }
156 143
157 private String findEpisodeName(String s, String se) { 144 private String findEpisodeName(String s, String se) {
158 this.capitalize(s.substring(0, s.indexOf(se)) 145
146 s.substring(0, s.indexOf(se))
159 .replaceAll("\\.", "\\ ") 147 .replaceAll("\\.", "\\ ")
160 .replaceAll("'", "") 148 .replaceAll("'", "")
161 .trim()) 149 .replaceAll("_", " ")
150 .trim()
151 .split(' ')
152 .collect { it.capitalize() }
153 .join(' ')
162 } 154 }
163} 155}
164 156