diff options
author | Guillermo Ramos | 2012-05-06 21:54:20 +0200 |
---|---|---|
committer | Guillermo Ramos | 2012-05-06 21:54:20 +0200 |
commit | b0ce25e6d3d77c18c958578fdbdae92654e46c93 (patch) | |
tree | ca0909a655f41061b1b6699ce531443be32502ad /scala/censor.scala | |
parent | e17d06cbdd0eae3fcc193c345f787a28cb031cea (diff) | |
download | 7l-b0ce25e6d3d77c18c958578fdbdae92654e46c93.tar.gz |
[Scala] Día 2
Diffstat (limited to 'scala/censor.scala')
-rw-r--r-- | scala/censor.scala | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/scala/censor.scala b/scala/censor.scala new file mode 100644 index 0000000..ed9bf0d --- /dev/null +++ b/scala/censor.scala @@ -0,0 +1,27 @@ +import scala.collection.mutable.HashMap + +trait Censor { + var curses = new HashMap[String, String] + + def loadCurses(s: String) = { + val lines = scala.io.Source.fromFile(s).getLines + lines.foreach(line => {val kv = line.split('='); curses(kv(0)) = kv(1)}) + } + + def nice(s: String) = { + var clean = s + curses.foreach(m => clean = clean.replaceAll(m._1, m._2)) + clean + } +} + +class Repeater extends Censor { + def repeatForever = { + while (true) + println(nice(readLine)) + } +} + +val myRepeater = new Repeater +myRepeater.loadCurses("censor.txt") +myRepeater.repeatForever |