Skip to content

Commit

Permalink
Added cap_sentence (#25)
Browse files Browse the repository at this point in the history
* Added cap_sentence

* Update README.md

* Update README.md

* Update README.md

* Update README.md
  • Loading branch information
raratiru authored Mar 29, 2020
1 parent 1eb0a16 commit 8809d58
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ Lia
Lia is here to take a detailed look at your strings.

* `pop_wsp`: Remove extra whitespace.
* `pre_slug`: Prepare a string to become a wise slug. 'r33a!bc' -> 'r 33 abc'.
* `fast_pre_slug`: Prepare a string to become a fast slug. 'r33a!bc' -> 'r 3 3 a bc'.
* `pre_slug`: Prepare a string to become a wise slug.
* 'r33a!bc' -> 'r 33 abc'.
* `fast_pre_slug`: Prepare a string to become a fast slug.
* 'r33a!bc' -> 'r 3 3 a bc'.
* `cap_sentence`: Carefully capitalize first letter and remove white space
* "O'Connor is        INVITED to UK" -> "O'Connor Is Invited To UK"

Matina
------
Expand Down
4 changes: 2 additions & 2 deletions thepysec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#
# Creation Date : Fri 28 Dec 2018 03:36:03 PM EET
#
# Last Modified : Mon 28 Oct 2019 06:44:46 PM EET (18:44)
# Last Modified : Mon 30 Mar 2020 01:33:58 AM EEST (01:33)
#
# ==============================================================================

from thepysec.john.version import get_version


VERSION = (2, 0, 1, "final", 0)
VERSION = (2, 0, 2, "final", 0)

__version__ = get_version(VERSION)
17 changes: 16 additions & 1 deletion thepysec/lia.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# Creation Date : Sat 16 Mar 2019 03:12:18 PM EET (15:12)
#
# Last Modified : Mon 28 Oct 2019 06:55:03 PM EET (18:55)
# Last Modified : Mon 30 Mar 2020 01:24:44 AM EEST (01:24)
#
# ==============================================================================

Expand Down Expand Up @@ -136,3 +136,18 @@ def pre_slug(s):
unidecode(s.translate(str.maketrans(punctuation)).lower()),
).split()
)


def cap_sentence(s):
"""
* Remove extra space
* Lower all letters if word.isupper() and len(word) > 3
* Capitalize the first letter of each word
"""
sentence = " ".join(
[c.lower() if c.isupper() and len(c) > 3 else c for c in s.split()]
)
return "".join(
c.upper() if i == 0 or sentence[i - 1] == " " else c
for i, c in enumerate(sentence)
)
9 changes: 8 additions & 1 deletion thepysec/tests/test_lia.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# Creation Date : Sat 16 Mar 2019 03:19:11 PM EET (15:19)
#
# Last Modified : Mon 28 Oct 2019 06:56:13 PM EET (18:56)
# Last Modified : Mon 30 Mar 2020 01:23:25 AM EEST (01:23)
#
# ==============================================================================

Expand All @@ -28,3 +28,10 @@ def test_pre_slug():
def test_fast_pre_slug():
raw_slug = "tr4e, 5435 (bili#go)"
assert lia.fast_pre_slug(raw_slug) == "tr 4 e 5 4 3 5 bili go"


def test_cap_sentence():
sentence = "O'Connor is INVITED to UK shortly after our friend's birthday"
assert lia.cap_sentence(sentence) == (
"O'Connor Is Invited To UK Shortly After Our Friend's Birthday"
)

0 comments on commit 8809d58

Please sign in to comment.