19 lines
481 B
Elixir
19 lines
481 B
Elixir
defmodule Mercury.Cleaners.Author do
|
|
import Mercury.Utils.Text, only: [normalize_spaces: 1]
|
|
|
|
@clean_author ~r/^\s*(posted |written )?by\s*:?\s*(.*)/i
|
|
|
|
@doc """
|
|
Take an author string (like 'by David Smith ') and clean it to just the name.
|
|
|
|
## Examples
|
|
|
|
iex> Mercury.Cleaners.Author.clean_author("by David Smith")
|
|
"David Smith"
|
|
"""
|
|
def clean_author(author) do
|
|
Regex.replace(@clean_author, normalize_spaces(author), "\\2")
|
|
|> String.trim()
|
|
end
|
|
end
|