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
ehbrs-tools-0.24.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.8.0 lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.23.1 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.23.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.7.2 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.7.1 lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.22.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.21.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.20.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.19.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.18.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.17.0 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.16.5 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.16.4 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.16.3 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.16.2 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.7.0 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.6.1 lib/aranha/parsers/html/node/base.rb
ehbrs-tools-0.16.1 vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.6.0 lib/aranha/parsers/html/node/base.rb