class HtmlLinksToTextInterceptor::LinkScrubber
A specialized Scrubber to convert HTML links to text
Public Instance Methods
scrub(node)
click to toggle source
# File lib/html_links_to_text_interceptor.rb, line 11 def scrub(node) replace_link_node_with_text_node(node) if link?(node) end
Private Instance Methods
build_text_node_from_link(node)
click to toggle source
# File lib/html_links_to_text_interceptor.rb, line 17 def build_text_node_from_link(node) link_text_node = node.children.first link_text_node.content = "#{link_text_node}: #{extract_url(node)}" link_text_node end
extract_url(node)
click to toggle source
# File lib/html_links_to_text_interceptor.rb, line 23 def extract_url(node) href = node.attributes["href"] return nil unless href href.value end
link?(node)
click to toggle source
# File lib/html_links_to_text_interceptor.rb, line 29 def link?(node) node.name == "a" end
replace_link_node_with_text_node(node)
click to toggle source
# File lib/html_links_to_text_interceptor.rb, line 33 def replace_link_node_with_text_node(node) link_as_text = build_text_node_from_link(node) node.before link_as_text node.remove end