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
aranha-parsers-0.21.0 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.20.0 lib/aranha/parsers/html/node/base.rb
eac_tools-0.69.1 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.19.1 lib/aranha/parsers/html/node/base.rb
eac_tools-0.69.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.68.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.19.0 lib/aranha/parsers/html/node/base.rb
eac_tools-0.67.1 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.67.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.66.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.65.1 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.18.0 lib/aranha/parsers/html/node/base.rb
eac_tools-0.65.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.64.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.63.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.62.1 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.62.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.61.1 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.61.0 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb
eac_tools-0.60.3 sub/aranha-parsers/lib/aranha/parsers/html/node/base.rb