diff options
Diffstat (limited to 'cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/soundexmetric.scala')
-rwxr-xr-x | cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/soundexmetric.scala | 53 |
1 files changed, 15 insertions, 38 deletions
diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/soundexmetric.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/soundexmetric.scala index 01d070e..c7ec0cd 100755 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/soundexmetric.scala +++ b/cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/soundexmetric.scala @@ -3,42 +3,19 @@ package com.rockymadden.stringmetric.cli.phonetic import com.rockymadden.stringmetric.cli._ import com.rockymadden.stringmetric.phonetic.SoundexMetric -/** - * The soundexmetric [[com.rockymadden.stringmetric.cli.Command]]. Compares two strings to determine if they are - * phonetically similarly, per the Soundex algorithm. - */ -object soundexmetric extends Command { - override def main(args: Array[String]): Unit = { - val options: OptionMap = args - - try - if (options.contains('h) || options.contains('help)) { - help() - exit(options) - } else if (options.contains('dashless) && (options('dashless): Array[String]).length == 2) { - execute(options) - exit(options) - } else throw new IllegalArgumentException("Expected valid syntax. See --help.") - catch { case e: Throwable => error(e, options) } - } - - override def help(): Unit = { - val ls = sys.props("line.separator") - val tab = " " - - println( - "Compares two strings to determine if they are phonetically similarly, per the Soundex algorithm." + ls + ls + - "Syntax:" + ls + - tab + "soundexmetric [Options] string1 string2..." + ls + ls + - "Options:" + ls + - tab + "-h, --help" + ls + - tab + tab + "Outputs description, syntax, and options." - ) - } - - override def execute(options: OptionMap): Unit = { - val strings: Array[String] = options('dashless) - - println(SoundexMetric.compare(strings(0), strings(1)).getOrElse("not comparable")) +case object soundexmetric extends Command( + (opts) => + "Compares two strings to determine if they are phonetically similarly, per the Soundex algorithm." + Ls + Ls + + "Syntax:" + Ls + + Tab + "soundexmetric [Options] string1 string2..." + Ls + Ls + + "Options:" + Ls + + Tab + "-h, --help" + Ls + + Tab + Tab + "Outputs description, syntax, and options.", + (opts) => opts.contains('dashless) && (opts('dashless): Array[String]).length == 2, + (opts) => { + val strings: Array[String] = opts('dashless) + SoundexMetric.compare(strings(0), strings(1)) + .map(_.toString) + .getOrElse("not comparable") } -} +) |