Sha256: 13c223dcc3264df002a1fcab21fee89604eb3d58072cb5b966ce8e26933ec91d
Contents?: true
Size: 1.61 KB
Versions: 3
Compression:
Stored size: 1.61 KB
Contents
require 'nokogiri' module MetaInspector ## # Parses the document with Nokogiri. # # Delegates the parsing of the different elements to specialized parsers, # passing itself as a reference for coordination purposes # class Parser def initialize(document, options = {}) @document = document @head_links_parser = MetaInspector::Parsers::HeadLinksParser.new(self) @meta_tag_parser = MetaInspector::Parsers::MetaTagsParser.new(self) @links_parser = MetaInspector::Parsers::LinksParser.new(self) @download_images = options[:download_images] @images_parser = MetaInspector::Parsers::ImagesParser.new(self, download_images: @download_images) @texts_parser = MetaInspector::Parsers::TextsParser.new(self) parsed # parse early so we can fail early end extend Forwardable delegate [:url, :scheme, :host] => :@document delegate [:meta_tags, :meta_tag, :meta, :charset] => :@meta_tag_parser delegate [:head_links, :stylesheets, :canonicals, :feed] => :@head_links_parser delegate [:links, :base_url] => :@links_parser delegate :images => :@images_parser delegate [:title, :best_title, :author, :best_author, :description, :best_description] => :@texts_parser # Returns the whole parsed document def parsed @parsed ||= Nokogiri::HTML(@document.to_s) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
metainspector-5.7.0 | lib/meta_inspector/parser.rb |
metainspector-5.6.0 | lib/meta_inspector/parser.rb |
metainspector-5.5.0 | lib/meta_inspector/parser.rb |