Sha256: 7b1c548408f40a9e396b4c4af2cb5b09f9cde5f758cf3d9f2eb7aa789b611fff

Contents?: true

Size: 803 Bytes

Versions: 67

Compression:

Stored size: 803 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.map do |f|
              [f[0], parse_field(node, f[2], f[1])]
            rescue StandardError => e
              raise StandardError, "#{e.message}\nFields: #{f}"
            end.to_h
          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

67 entries across 67 versions & 2 rubygems

Version Path
eac_tools-0.40.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.39.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.14.4 lib/aranha/parsers/html/node/base.rb
eac_tools-0.38.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.14.3 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.14.2 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.14.1 lib/aranha/parsers/html/node/base.rb