Class: TheScrap::Scrap
- Inherits:
-
Object
- Object
- TheScrap::Scrap
- Defined in:
- lib/the_scrap/scrap.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
图片,连接base url.
-
#data_proc ⇒ Object
抓取完内容后手工对数据进行加工.
-
#debug ⇒ Object
(also: #debug?)
Returns the value of attribute debug.
-
#detail_info ⇒ Object
详细页面对象.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#html_proc ⇒ Object
获取页面html后的处理方法.
-
#item_frag ⇒ Object
条目.
-
#result_proc ⇒ Object
入库,文件生成等。.
-
#url ⇒ Object
起点URL.
-
#verbose ⇒ Object
(also: #verbose?)
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize ⇒ Scrap
constructor
A new instance of Scrap.
- #method_missing(method_id, *arguments, &block) ⇒ Object
- #retryable(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Scrap
Returns a new instance of Scrap.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/the_scrap/scrap.rb', line 26 def initialize() @attrs = {} @more_info = [] @debug = false #@encoding = 'utf-8' @result_proc = [] @detail_info = [] @data_proc = [] @html_proc = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/the_scrap/scrap.rb', line 54 def method_missing( method_id, *arguments, &block ) if(method_id =~ /attr_(.*)=/) name = $~[1] @attrs[name] = arguments.first end end |
Instance Attribute Details
#base_url ⇒ Object
图片,连接base url
12 13 14 |
# File 'lib/the_scrap/scrap.rb', line 12 def base_url @base_url end |
#data_proc ⇒ Object
抓取完内容后手工对数据进行加工
14 15 16 |
# File 'lib/the_scrap/scrap.rb', line 14 def data_proc @data_proc end |
#debug ⇒ Object Also known as: debug?
Returns the value of attribute debug.
20 21 22 |
# File 'lib/the_scrap/scrap.rb', line 20 def debug @debug end |
#detail_info ⇒ Object
详细页面对象
16 17 18 |
# File 'lib/the_scrap/scrap.rb', line 16 def detail_info @detail_info end |
#encoding ⇒ Object
Returns the value of attribute encoding.
18 19 20 |
# File 'lib/the_scrap/scrap.rb', line 18 def encoding @encoding end |
#html_proc ⇒ Object
获取页面html后的处理方法
13 14 15 |
# File 'lib/the_scrap/scrap.rb', line 13 def html_proc @html_proc end |
#item_frag ⇒ Object
条目
10 11 12 |
# File 'lib/the_scrap/scrap.rb', line 10 def item_frag @item_frag end |
#result_proc ⇒ Object
入库,文件生成等。
15 16 17 |
# File 'lib/the_scrap/scrap.rb', line 15 def result_proc @result_proc end |
#url ⇒ Object
起点URL
11 12 13 |
# File 'lib/the_scrap/scrap.rb', line 11 def url @url end |
#verbose ⇒ Object Also known as: verbose?
Returns the value of attribute verbose.
23 24 25 |
# File 'lib/the_scrap/scrap.rb', line 23 def verbose @verbose end |
Instance Method Details
#retryable(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/the_scrap/scrap.rb', line 37 def retryable( = {} ) opts = { :tries => 1, :on => Exception }.merge() retry_exception, retries = opts[:on], opts[:tries] begin return yield rescue retry_exception if (retries -= 1) > 0 sleep 2 retry else raise end end end |