diff options
author | tdro <tdro@users.noreply.github.com> | 2020-11-19 22:28:03 -0500 |
---|---|---|
committer | tdro <tdro@users.noreply.github.com> | 2020-11-19 22:48:37 -0500 |
commit | 6050c129bc7a1d87de51dde1e3c44c4e5f01d159 (patch) | |
tree | da7a5e49d8d71a3f7f45b89976b7944438585f08 /.local/bin/plumber | |
parent | 48b5b89dbe0d0ae68fafb3b38e5a3f90ed3cab76 (diff) | |
download | dotfiles-6050c129bc7a1d87de51dde1e3c44c4e5f01d159.tar.gz dotfiles-6050c129bc7a1d87de51dde1e3c44c4e5f01d159.tar.bz2 dotfiles-6050c129bc7a1d87de51dde1e3c44c4e5f01d159.zip |
.local/bin/plumber: Add crude text plumber
Diffstat (limited to '.local/bin/plumber')
-rwxr-xr-x | .local/bin/plumber | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/.local/bin/plumber b/.local/bin/plumber new file mode 100755 index 0000000..0c575b9 --- /dev/null +++ b/.local/bin/plumber @@ -0,0 +1,34 @@ +#! /usr/bin/env elixir + +defmodule ArgParser do + def parse do + {opts, _} = + System.argv() + |> OptionParser.parse!(strict: [option: :string, text: :string]) + + cond do + opts[:option] == "First letter of each word in sentence" -> + TextPlumber.firstLetterOfWordsIn(opts[:text]) + + opts[:option] == "Single line of text" -> + TextPlumber.singleLineOf(opts[:text]) + + true -> + "No plumber specified #{opts[:option]}" |> IO.puts() + end + end +end + +defmodule TextPlumber do + def firstLetterOfWordsIn(text) do + String.replace(text, ~r/(\w)\w*/, "\\1", global: true) + |> String.replace(~r/\s\s+/, " ", global: true) + |> IO.puts() + end + + def singleLineOf(text) do + String.replace(text, "\n", "") |> IO.puts() + end +end + +ArgParser.parse() |