Sha256: 7a35ecfa6b1932358d6300d91a9a7a0cd7f1d86cd61fa91fcbed30cf10570125

Contents?: true

Size: 707 Bytes

Versions: 3

Compression:

Stored size: 707 Bytes

Contents

module Scrapify
  class Scraper
    def initialize(url, key_attr, attributes)
      @scraper = Class.new
      @scraper.send(:include, Scrapify::Base)
      @scraper.html url
      @scraper.key key_attr.to_sym
      attributes.symbolize_keys.each do |attr, options|
        options = options.symbolize_keys
        custom_block = options.delete(:block)
        @scraper.attribute attr, options, &custom_block
      end
    end

    def method_missing(method, *args, &block)
      return @scraper.send(method, *args, &block) if @scraper.respond_to?(method)
      super
    end

    def respond_to?(method, include_private=false)
      @scraper.respond_to?(method, include_private) || super
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scrapify-0.0.9 lib/scrapify/scraper.rb
scrapify-0.0.8 lib/scrapify/scraper.rb
scrapify-0.0.7 lib/scrapify/scraper.rb