Created
August 25, 2010 15:24
-
-
Save lucianosousa/549703 to your computer and use it in GitHub Desktop.
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
def wtruncate(text, length) | |
text = text.encode_utf8 | |
if text.length > length | |
sum = 0 | |
words_ret = [] | |
words = text.split(' ') | |
words.each do |word| | |
sum += word.length + 1 | |
break if sum > length | |
words_ret << word | |
end | |
words_ret = words_ret.join(' ') | |
words_ret << "..." | |
else | |
text | |
end | |
end |
adicionando retirencias
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
alterei para o text para text.encode_utf8, para particularidades