blob: 5d7b0bc634cb6b37befed6c757a60f22abe4d9fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#! /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", " ")
|> String.replace(~r/\s\s+/, " ", global: true)
|> IO.puts()
end
end
ArgParser.parse()
|