Class: Ruby2ch::Thre

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Thre

Returns a new instance of Thre.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby2ch/thre.rb', line 6

def initialize(url)
  @agent = Mechanize.new
  @page = @agent.get(url)
  @title = (@page/"h1").text
  @res = (@page/"dd").map{|r| r.text}
  @name = (@page/"dt").map{|n| n.text}
  @name.map!{|nn| nn.split(":")}
  @no = @name.map{|n| n[0]}
  @hn = @name.map{|n| n[1]}
  name_split = @name.map{|n| n[2].split(" ")} 
  @ids = name_split.map{|n| n[2]}.uniq.map{|id| 
    puts id
    id.sub("ID:","")}
  @date1 = name_split.map{|n| n[0]}.map{|n| n.sub(/\(.\)/,"")}
  @time = name_split.map{|n| n[1]}
  @date = @date1[0] + " " + @time[0]
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



28
29
30
# File 'lib/ruby2ch/thre.rb', line 28

def date
  @date
end

#idsObject

Returns the value of attribute ids.



28
29
30
# File 'lib/ruby2ch/thre.rb', line 28

def ids
  @ids
end

#titleObject

Returns the value of attribute title.



28
29
30
# File 'lib/ruby2ch/thre.rb', line 28

def title
  @title
end

Instance Method Details

#impetusObject



24
25
26
# File 'lib/ruby2ch/thre.rb', line 24

def impetus
  return @res.size/(Time.now - Time.parse(@date)) * 60 * 60 * 24
end