Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 30th, 2012  |  syntax: None  |  size: 0.40 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Each paragraph consists of a bunch of children. Some are text, some are tags, like <i>, with their own children (the content of the tags).
  2. #
  3. # This implies that in order to get *just* the text, without any markup, we'll need a recursive function to get all the text.
  4.  
  5.  
  6. def just_text el
  7.   s = ""
  8.   el.children.each do |child|
  9.     s += (child.name == "text") ? child.text : just_text(child)
  10.   end
  11.   s
  12. end