Sha256: 182538fc5cdb89718c11296be80035b9f93d4b2377e868b9c8a2838b7d9689d8

Contents?: true

Size: 669 Bytes

Versions: 1

Compression:

Stored size: 669 Bytes

Contents

module Harvestman
  module Crawler
    class Parser
      def initialize(url)
        @document = Nokogiri::HTML(open(url))
      end

      def css(path, &block)
        parse(:css, path, &block)
      end

      def xpath(path, &block)
        parse(:xpath, path, &block)
      end

      private

      def parse(path_type, path, &block)
        if block_given?
          @document.send(path_type, path).each do |node|
            doc = @document
            @document = node
            instance_eval(&block)
            @document = doc
          end
        else
          @document.send("at_#{path_type}", path).inner_text
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
harvestman-0.1.1 lib/harvestman/crawler/parser.rb