Sha256: fc9f92e2cb642a89e95d176789bc201e9bb14618ca55f7c8fbed9218246862b5

Contents?: true

Size: 673 Bytes

Versions: 16

Compression:

Stored size: 673 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)
            Hash[fields.map { |f| [f[0], parse_field(node, f[2], f[1])] }]
          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

16 entries across 16 versions & 2 rubygems

Version Path
aranha-parsers-0.1.1 lib/aranha/parsers/html/node/base.rb
aranha-parsers-0.1.0 lib/aranha/parsers/html/node/base.rb
aranha-0.10.1 lib/aranha/parsers/html/node/base.rb
aranha-0.10.0 lib/aranha/parsers/html/node/base.rb
aranha-0.9.1 lib/aranha/parsers/html/node/base.rb
aranha-0.9.0 lib/aranha/parsers/html/node/base.rb
aranha-0.8.0 lib/aranha/parsers/html/node/base.rb
aranha-0.7.1 lib/aranha/parsers/html/node/base.rb
aranha-0.7.0 lib/aranha/parsers/html/node/base.rb
aranha-0.6.0 lib/aranha/parsers/html/node/base.rb
aranha-0.5.0 lib/aranha/parsers/html/node/base.rb
aranha-0.4.0 lib/aranha/parsers/html/node/base.rb
aranha-0.3.0 lib/aranha/parsers/html/node/base.rb
aranha-0.2.1 lib/aranha/parsers/html/node/base.rb
aranha-0.2.0 lib/aranha/parsers/html/node/base.rb
aranha-0.1.0 lib/aranha/parsers/html/node/base.rb