Class: Scrapify::Scraper
- Inherits:
-
Object
- Object
- Scrapify::Scraper
- Defined in:
- lib/scrapify/scraper.rb
Instance Method Summary collapse
-
#initialize(url, key_attr, attributes) ⇒ Scraper
constructor
A new instance of Scraper.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(method, include_private = false) ⇒ Boolean
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, | = .symbolize_keys custom_block = .delete(:block) @scraper.attribute attr, , &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
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 |