Sha256: 61f1a773ec1ceced9cb1e6332245244cddd1292acbfb1860746af49d1268a3ff

Contents?: true

Size: 1.43 KB

Versions: 14

Compression:

Stored size: 1.43 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, :description]             => :@texts_parser

    # Returns the whole parsed document
    def parsed
      @parsed ||= Nokogiri::HTML(@document.to_s)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
metainspector-5.3.1 lib/meta_inspector/parser.rb
metainspector-5.3.0 lib/meta_inspector/parser.rb
metainspector-5.2.3 lib/meta_inspector/parser.rb
metainspector-5.2.2 lib/meta_inspector/parser.rb
metainspector-5.2.1 lib/meta_inspector/parser.rb
metainspector-5.2.0 lib/meta_inspector/parser.rb
metainspector-5.1.3 lib/meta_inspector/parser.rb
metainspector-5.1.2 lib/meta_inspector/parser.rb
metainspector-5.1.1 lib/meta_inspector/parser.rb
metainspector-5.1.0 lib/meta_inspector/parser.rb
metainspector-5.0.2 lib/meta_inspector/parser.rb
metainspector-5.0.1 lib/meta_inspector/parser.rb
metainspector-5.0.0 lib/meta_inspector/parser.rb
metainspector-5.0.0.rc1 lib/meta_inspector/parser.rb