Hey all

I have a bunch of html in p tags and i want to show shorted summary -
like the first 25 words followed by '...'.  I also want to strip out any
images.  I'm using hpricot for this and am finding myself writing a
convoluted messy method.  Can anyone show me a clean and simple way?  Is
Hpricot even the right tool for the job?

Here's the hacky and not-really-to-spec mess i have so far.

    def lede(word_count = 25)
      doc = self.hpricot_body
      #wipe images
      doc.search("img").remove
      paras = doc.search("//p")
      text = ""
      while paras.size > 0 && text.split(" ").size < word_count
        text += paras.shift.to_html
      end
      if (arr = text.split(" ")).size > 25
        return arr[0..24].join(" ") + " ..."
      else
        return arr.join(" ")
      end
    end

thanks
max
-- 
Posted via http://www.ruby-forum.com/.