Class: Ruby2ch::Board

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2ch/board.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Board



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby2ch/board.rb', line 9

def initialize(url)
  @agent = Mechanize.new
  url = url + "subback.html"
  @page = @agent.get(url)
  @links = @page.links.map{|link| [link.href,link.text]}#.map{|link| link.split("/")[0]}

  @links.map!{|link,title|  [link.split("/")[0],title]}

  @links.map!{|link,title| 
    [url.sub("/news/subback.html","/test/read.cgi/news/") + link,title]}
  
  @links.select!{|link,title| /\/\d*$/ =~link}
end

Instance Attribute Details

Returns the value of attribute links.



38
39
40
# File 'lib/ruby2ch/board.rb', line 38

def links
  @links
end

Instance Method Details

#threads(num) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby2ch/board.rb', line 23

def threads(num)
  threads = []
  thread_num = 100
  num.times{|i|
    threads << Thread.start(i){|i| Dat.new(@links[i][0],@links[i][1])}
  }

  threads.map!{|thre|
    thre.join.value
  }

  return threads

end