Sha256: 5dd6db246d92e53c79178f1c93d6d376493404f51e7fa1a5fac5729245df5e7f
Contents?: true
Size: 1.07 KB
Versions: 16
Compression:
Stored size: 1.07 KB
Contents
module MetaInspector module Parsers class HeadLinksParser < Base delegate [:parsed, :base_url] => :@main_parser def head_links @head_links ||= parsed.css('head link').map do |tag| Hash[ tag.attributes.keys.map do |key| keysym = key.to_sym val = tag.attributes[key].value val = URL.absolutify(val, base_url) if keysym == :href [keysym, val] end ] end end def stylesheets @stylesheets ||= head_links.select { |hl| hl[:rel] == 'stylesheet' } end def canonicals @canonicals ||= head_links.select { |hl| hl[:rel] == 'canonical' } end # Returns the parsed document meta rss link def feed @feed ||= (parsed_feed('rss') || parsed_feed('atom')) end private def parsed_feed(format) feed = parsed.search("//link[@type='application/#{format}+xml']").find{|link| link.attributes["href"] } feed ? URL.absolutify(feed['href'], base_url) : nil end end end end
Version data entries
16 entries across 16 versions & 1 rubygems