lib/pricecut/elements/text.rb in pricecut-0.0.2 vs lib/pricecut/elements/text.rb in pricecut-0.0.3

- old
+ new

@@ -1,9 +1,32 @@ module Pricecut module Elements class Text < Element def output! - p node.text.strip + return if whitespace_only? + + output = node.text + + output.tr!("\n", " ") + output.squeeze!(" ") + + output.lstrip! unless previous_sibling? + output.rstrip! unless next_sibling? + + p output + end + + private + def whitespace_only? + node.blank? + end + + def previous_sibling? + node.previous_sibling + end + + def next_sibling? + node.next_sibling end end end end \ No newline at end of file