Guest User

Untitled

a guest
Jun 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. def truncate(text, max_sentences = 3, max_words = 50)
  2. # Take first 3 setences (blah. blah. blah)
  3. three_sentences = text.split('. ').slice(0, max_sentences).join('. ')
  4. # Take first 50 words of the above
  5. shortened = three_sentences.split(' ').slice(0, max_words).join(' ')
  6. return shortened # bah, explicit return is evil
  7. end
  8.  
  9. stories.split(' ').slice(0,50).join(' ')
  10.  
  11. class String
  12. def to_blurb(word_count = 30)
  13. self.split(" ").slice(0, word_count).join(" ")
  14. end
  15. end
  16.  
  17. require 'core_extensions'
Add Comment
Please, Sign In to add comment