Class: MetaInspector::Parser

Inherits:
Object
  • Object
show all
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

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, options = {})
  @document        = document
  @exception_log   = options[: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 = 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

Instance Method Details

#parsedObject

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