Class: TheScrap::Scrap

Inherits:
Object
  • Object
show all
Defined in:
lib/the_scrap/scrap.rb

Direct Known Subclasses

DetailObj, ListObj

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScrap

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_urlObject

图片,连接base url



12
13
14
# File 'lib/the_scrap/scrap.rb', line 12

def base_url
  @base_url
end

#data_procObject

抓取完内容后手工对数据进行加工



14
15
16
# File 'lib/the_scrap/scrap.rb', line 14

def data_proc
  @data_proc
end

#debugObject 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_infoObject

详细页面对象



16
17
18
# File 'lib/the_scrap/scrap.rb', line 16

def detail_info
  @detail_info
end

#encodingObject

Returns the value of attribute encoding.



18
19
20
# File 'lib/the_scrap/scrap.rb', line 18

def encoding
  @encoding
end

#html_procObject

获取页面html后的处理方法



13
14
15
# File 'lib/the_scrap/scrap.rb', line 13

def html_proc
  @html_proc
end

#item_fragObject

条目



10
11
12
# File 'lib/the_scrap/scrap.rb', line 10

def item_frag
  @item_frag
end

#result_procObject

入库,文件生成等。



15
16
17
# File 'lib/the_scrap/scrap.rb', line 15

def result_proc
  @result_proc
end

#urlObject

起点URL



11
12
13
# File 'lib/the_scrap/scrap.rb', line 11

def url
  @url
end

#verboseObject 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( options = {} )
  opts = { :tries => 1, :on => Exception }.merge(options)

  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