-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from mariosant/add-sentence-case
Add sentence case
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule Recase.SentenceCase do | ||
@moduledoc """ | ||
Module to convert strings to `Sentence case`. | ||
This module should not be used directly. | ||
Read about `Sentence case` here: | ||
https://en.wikipedia.org/wiki/Letter_case#Sentence_case | ||
""" | ||
|
||
alias Recase.SnakeCase | ||
|
||
@sep " " | ||
|
||
@spec convert(String.t) :: String.t | ||
def convert(""), do: "" | ||
def convert(value) do | ||
value | ||
|> SnakeCase.convert | ||
|> String.replace("_", @sep) | ||
|> String.capitalize | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule Recase.SentenceCaseTest do | ||
use ExUnit.Case | ||
|
||
import Recase.SentenceCase | ||
|
||
doctest Recase.SentenceCase | ||
|
||
test "should sentence case usual text" do | ||
assert convert("sentence case") == "Sentence case" | ||
assert convert("sentenceCase") == "Sentence case" | ||
assert convert("sentence_Case") == "Sentence case" | ||
assert convert("sentenceCase") == "Sentence case" | ||
assert convert("sentence.Case") == "Sentence case" | ||
assert convert("Sentence case") == "Sentence case" | ||
assert convert("--sentence-case--") == "Sentence case" | ||
assert convert("sentence#case") == "Sentence case" | ||
assert convert("sentence?!case") == "Sentence case" | ||
end | ||
|
||
test "should return empty string" do | ||
assert convert("") == "" | ||
end | ||
end |