Class: MetaInspector::Parser
- Inherits:
-
Object
- Object
- MetaInspector::Parser
- Extended by:
- Forwardable
- Includes:
- Exceptionable
- Defined in:
- lib/meta_inspector/parser.rb
Overview
Parses the document with Nokogiri.
Delegates the parsing of the different elements to specialized parsers, passing itself as a reference for coordination purposes
Instance Method Summary collapse
-
#initialize(document, options = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parsed ⇒ Object
Returns the whole parsed document.
Constructor Details
#initialize(document, options = {}) ⇒ Parser
Returns a new instance of Parser.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/meta_inspector/parser.rb', line 13 def initialize(document, = {}) @document = document @exception_log = [:exception_log] @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 = [: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 |
Instance Method Details
#parsed ⇒ Object
Returns the whole parsed document
35 36 37 38 39 |
# File 'lib/meta_inspector/parser.rb', line 35 def parsed @parsed ||= Nokogiri::HTML(@document.to_s) rescue Exception => e @exception_log << e end |