Sha256: c2d890f9e86abf40616f49acdcbc80a0026bf0b5ffbd5377c1f0f0ff03559e8c
Contents?: true
Size: 1.15 KB
Versions: 3
Compression:
Stored size: 1.15 KB
Contents
module Murlsh # Nokogiri / Hpricot doc mixin. module Doc # Get the character set of the document. def charset %w{content-type Content-Type}.each do |ct| content_type = at("meta[@http-equiv='#{ct}']") unless content_type.nil? content = content_type['content'] unless content.nil? charset = content[/charset=([\w.:-]+)/, 1] return charset if charset end end end nil end # 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) [*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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
murlsh-1.3.1 | lib/murlsh/doc.rb |
murlsh-1.3.0 | lib/murlsh/doc.rb |
murlsh-1.2.1 | lib/murlsh/doc.rb |