Sha256: 3e5fa98def2644c7ec3546f9e12dca477006368144145e5e9da850c7643a8b1f

Contents?: true

Size: 847 Bytes

Versions: 46

Compression:

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

46 entries across 46 versions & 2 rubygems

Version Path
aranha-parsers-0.14.0 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.13.0 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.12.1 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.12.0 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.11.0 lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.28.3 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.10.0 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.9.0 lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.28.2 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.28.1 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.28.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.27.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.8.5 lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.26.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.8.4 lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.25.1 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.25.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.8.3 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.8.2 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.8.1 lib/aranha/parsers/html/node/base.rb