Sha256: de8ce395b10dfbf0599c8aa87b2450756e81faa7d398ee6a51bfbe43d4490a6e
Contents?: true
Size: 749 Bytes
Versions: 7
Compression:
Stored size: 749 Bytes
Contents
module Murlsh # Nokogiri doc mixin. module Doc # Check a list of xpaths in order and yield and return the node matching # the first one that is not nil def xpath_search(xpaths) Array(xpaths).each do |xpath| selection = (self/xpath).first if selection; return (yield selection); end end nil end # Get the title of the document. def title xpath_search(%w{ //html/head/title //head/title //html/title //title }) { |node| node.inner_html } end # Get the meta description of the document. def description xpath_search( "//html/head/meta[@name='description']" ) { |node| node['content'] } end end end
Version data entries
7 entries across 7 versions & 1 rubygems