Class: Botz::Definition
- Inherits:
-
Object
- Object
- Botz::Definition
- Defined in:
- lib/botz/definition.rb
Overview
Class representing a website defined by DSL
Class Method Summary collapse
- .scraper(name, options, &block) ⇒ Object
- .spider(name, start_url = nil, encoding: nil, as: :html, &block) ⇒ Object
Instance Method Summary collapse
Class Method Details
.scraper(name, options, &block) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/botz/definition.rb', line 34 def scraper(name, , &block) if [:loop] loop_scraper(name, , &block) else normal_scraper(name, **, &block) end end |
.spider(name, start_url = nil, encoding: nil, as: :html, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/botz/definition.rb', line 18 def spider(name, start_url = nil, encoding: nil, as: :html, &block) connector_class = Botz::Connector.const_get(as.to_s.classify) connector = connector_class.new(start_url: start_url, encoding: encoding) spider = Botz::Spider.new(&block) spider_class = Class.new do define_singleton_method(:connector) { connector } define_singleton_method(:call) do |url = start_url, &spider_block| connector.call(url) do |resource| spider.call(resource, &spider_block) end end end const_set("#{name}_spider".classify, spider_class) spiders[name] = spider_class end |
Instance Method Details
#output(&block) ⇒ Object
12 13 14 |
# File 'lib/botz/definition.rb', line 12 def output(&block) self.output = block end |