diff options
Diffstat (limited to 'cli/source/core/scala/com/rockymadden/stringmetric/cli/phonetic/refinedsoundexalgorithm.scala')
-rwxr-xr-x | cli/source/core/scala/com/rockymadden/stringmetric/cli/phonetic/refinedsoundexalgorithm.scala | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/cli/source/core/scala/com/rockymadden/stringmetric/cli/phonetic/refinedsoundexalgorithm.scala b/cli/source/core/scala/com/rockymadden/stringmetric/cli/phonetic/refinedsoundexalgorithm.scala new file mode 100755 index 0000000..f5a89a8 --- /dev/null +++ b/cli/source/core/scala/com/rockymadden/stringmetric/cli/phonetic/refinedsoundexalgorithm.scala @@ -0,0 +1,41 @@ +package com.rockymadden.stringmetric.cli.phonetic + +import com.rockymadden.stringmetric.cli._ +import com.rockymadden.stringmetric.phonetic.RefinedSoundexAlgorithm + +/** + * The refinedsoundexalgorithm [[com.rockymadden.stringmetric.cli.Command]]. Returns the phonetic representation of the + * passed string, per the refined Soundex algorithm. + */ +object refinedsoundexalgorithm extends Command { + override def main(args: Array[String]): Unit = { + val opts: OptionMap = args + + try + if (opts.contains('h) || opts.contains('help)) { + help() + exit(opts) + } else if (opts.contains('dashless) && (opts('dashless): Array[String]).length == 1) { + execute(opts) + exit(opts) + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") + catch { case e: Throwable => error(e, opts) } + } + + override def help(): Unit = { + val ls = sys.props("line.separator") + val tab = " " + + println( + "Returns the phonetic representation of the passed string, per the refined Soundex algorithm." + ls + ls + + "Syntax:" + ls + + tab + "refinedsoundexalgorithm [Options] string..." + ls + ls + + "Options:" + ls + + tab + "-h, --help" + ls + + tab + tab + "Outputs description, syntax, and opts." + ) + } + + override def execute(opts: OptionMap): Unit = + println(RefinedSoundexAlgorithm.compute(opts('dashless)).getOrElse("not computable")) +} |