Skip to content

Commit

Permalink
sep defaults to None to handle mutlitple spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdabbas committed Jan 21, 2018
1 parent 9d76c5e commit 84e94eb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions advertools/ad_from_string.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import string
def ad_from_string(s, slots=(30, 30, 80, 15, 15), sep=' ', capitalize=False):
def ad_from_string(s, slots=(30, 30, 80, 15, 15), sep=None, capitalize=False):
"""Convert string `s` to an ad by splitting it into groups of words.
Each group would have a length of at most the allowed length for that slot.
Expand Down Expand Up @@ -35,11 +35,11 @@ def ad_from_string(s, slots=(30, 30, 80, 15, 15), sep=' ', capitalize=False):

for i, slot in enumerate(slots):
while counter <= len(str_words) - 1:
if len(text_ad[i] + str_words[counter]) >= slot:
if len(text_ad[i] + str_words[counter]) > slot:
break
text_ad[i] += ' ' + str_words[counter] if text_ad[i] else str_words[counter]
counter += 1

text_ad[-1] = sep.join(str_words[counter:])
text_ad[-1] = sep.join(str_words[counter:]) if sep is not None else ' '.join(str_words[counter:])

return [string.capwords(x) if capitalize else x for x in text_ad]

0 comments on commit 84e94eb

Please sign in to comment.