lib/ruby-hackernews/domain/comment/comment.rb in ruby-hackernews-1.3.1 vs lib/ruby-hackernews/domain/comment/comment.rb in ruby-hackernews-1.3.2
- old
+ new
@@ -7,18 +7,23 @@
attr_reader :voting
attr_reader :user
attr_accessor :parent
- def initialize(text, voting, user_info, reply_link)
+ def initialize(text, voting, user_info, reply_link, absolute_link)
@text = text
@voting = voting
@user = user_info
@reply_link = reply_link
+ @absolute_link = absolute_link
@children = []
end
+ def id
+ return @absolute_link.split("=")[1].to_i
+ end
+
def <<(comment)
comment.parent = self
@children << comment
end
@@ -34,9 +39,13 @@
@children.send(method, *args, &block)
end
def self.newest(pages = 1)
return CommentService.new.get_new_comments(pages)
+ end
+
+ def self.find(id)
+ return CommentService.new.find_by_id(id)
end
def reply(text)
return false unless @reply_link
CommentService.new.write_comment(@reply_link, text)