Sha256: 7294d21ddac65bd6c52828330f8004f54558ff63e8cb639e8d1f8e1561c9fc29

Contents?: true

Size: 928 Bytes

Versions: 5

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

require_relative '../base'
require_relative 'node/default'

module Aranha
  module Parsers
    module Html
      class Base < ::Aranha::Parsers::Base
        class << self
          def fields
            @fields ||= []
            @fields.dup
          end

          def field(name, type, xpath)
            @fields ||= []
            @fields << Field.new(name, type, xpath)
          end

          Field = Struct.new(:name, :type, :xpath)
        end

        def nokogiri
          @nokogiri ||= Nokogiri::HTML(content, &:noblanks)
        end

        protected

        def node_parser_class
          ::Aranha::Parsers::Html::Node::Default
        end

        private

        def node_parser
          @node_parser ||= node_parser_class.new(fields)
        end

        def fields
          self.class.fields.map { |f| [f.name, f.type, f.xpath] }
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aranha-0.9.0 lib/aranha/parsers/html/base.rb
aranha-0.8.0 lib/aranha/parsers/html/base.rb
aranha-0.7.1 lib/aranha/parsers/html/base.rb
aranha-0.7.0 lib/aranha/parsers/html/base.rb
aranha-0.6.0 lib/aranha/parsers/html/base.rb