Class: Scrapify::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/scrapify/scraper.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, key_attr, attributes) ⇒ Scraper

Returns a new instance of Scraper.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/scrapify/scraper.rb', line 3

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



15
16
17
18
# File 'lib/scrapify/scraper.rb', line 15

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

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/scrapify/scraper.rb', line 20

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