Sha256: 1fa0e7d499cf1427f34d3e428634dc7105667f03cddd9f12e988d3e5b2f64906

Contents?: true

Size: 799 Bytes

Versions: 5

Compression:

Stored size: 799 Bytes

Contents

# frozen_string_literal: true

module Aranha
  module Parsers
    module Html
      module Node
        class Base
          attr_reader :fields

          def initialize(fields)
            @fields = fields
          end

          def parse(node)
            fields.to_h do |f|
              [f[0], parse_field(node, f[2], f[1])]
            rescue StandardError => e
              raise StandardError, "#{e.message}\nFields: #{f}"
            end
          end

          private

          def parse_field(node, xpath, parser_method)
            value_method = "#{parser_method}_value"
            return send(value_method, node, xpath) if respond_to?(value_method)

            raise "Method \"#{value_method}\" not found in #{self.class}"
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aranha-parsers-0.25.0 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.24.0 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.23.1 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.23.0 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.22.0 lib/aranha/parsers/html/node/base.rb