Sha256: 8b4ed0c8050fe8f339a4aeac6471506bbec3366ac78ff28d29d4e119d3f8862b
Contents?: true
Size: 1.32 KB
Versions: 8
Compression:
Stored size: 1.32 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 include MetaInspector::Exceptionable def initialize(document, options = {}) @document = document @exception_log = options[:exception_log] @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) end extend Forwardable delegate [:url, :scheme, :host] => :@document delegate [:meta_tags, :meta_tag, :meta, :charset] => :@meta_tag_parser delegate [:links, :feed, :base_url] => :@links_parser delegate :images => :@images_parser delegate [:title, :best_title, :description] => :@texts_parser # Returns the whole parsed document def parsed @parsed ||= Nokogiri::HTML(@document.to_s) rescue Exception => e @exception_log << e end end end
Version data entries
8 entries across 8 versions & 1 rubygems