Created
March 28, 2012 17:48
-
-
Save ahawthorne/2228664 to your computer and use it in GitHub Desktop.
ruby strip_tags and text_trim
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 strip_tags(text) | |
return text.gsub(/<\/?[^>]*>/, "") | |
end | |
def text_trim(text, len, trail = '...') | |
if len < text.size then | |
text.scan(/.{1,#{len}} /) do |match| | |
return match.rstrip + trail | |
break | |
end | |
else | |
return text | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment