Ruby snippet for flexible blurbing of text

Here's a cute little method I use for extracting blurbs from text. Specify a minimum character count as the argument, and the method returns a string containing the minimum text plus whatever it takes to reach the next period, question mark, or exclamation point.

def blurb(size=75)
  reg = Regexp.new ".{#{size}}[,;:-_\\w\\s]*[\.\!\?]"
  body.slice(reg)
end

0 comments: