Class: MetaInspector::Parser

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/meta_inspector/parser.rb', line 11

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

Instance Method Details

#parsedObject

Returns the whole parsed document



33
34
35
# File 'lib/meta_inspector/parser.rb', line 33

def parsed
  @parsed ||= Nokogiri::HTML(@document.to_s)
end