forked from stormy/Quora-Personal-Analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost.rb
More file actions
37 lines (29 loc) · 954 Bytes
/
Copy pathPost.rb
File metadata and controls
37 lines (29 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Post
attr_reader :title, :url, :votes, :voters, :comments, :content
def initialize(fragment)
@title = fragment.css('.answer_user').css('a').inner_text
@url = fragment.css('.answer_user').css('a')[0]['href']
@votes = fragment.css('.post_votes.light').css('strong').inner_text
@voters = build_voters(fragment.css('.post_votes_item').css('.user'))
@comments = build_comments(fragment)
@content = Content.new(fragment.search('div[@class="feed_item_answer"]'))
end
def build_comments(comment)
if comment.search('a[@class="view_comments supp "]').inner_text =~ /Add Comment/
[]
else
comment_list = []
comment.css('.comment_contents').each do |x|
comment_list << Comment.new(x)
end
comment_list
end
end
def build_voters(allvoters)
voter_list = []
allvoters.each_with_index do |x,i|
voter_list << Voter.new(x,i)
end
voter_list
end
end