Class: RubyHackernews::Comment
- Inherits:
-
Object
- Object
- RubyHackernews::Comment
show all
- Includes:
- Enumerable
- Defined in:
- lib/ruby-hackernews/domain/comment/comment.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(text_html, voting, user_info, reply_link, absolute_link, parent_link) ⇒ Comment
Returns a new instance of Comment.
12
13
14
15
16
17
18
19
20
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 12
def initialize(text_html, voting, user_info, reply_link, absolute_link, parent_link)
@text_html = text_html
@voting = voting
@user = user_info
@reply_link = reply_link
@absolute_link = absolute_link
@parent_link = parent_link
@children = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
51
52
53
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 51
def method_missing(method, *args, &block)
@children.send(method, *args, &block)
end
|
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
10
11
12
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 10
def parent
@parent
end
|
#text_html ⇒ Object
Returns the value of attribute text_html.
6
7
8
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 6
def text_html
@text_html
end
|
#user ⇒ Object
Returns the value of attribute user.
8
9
10
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 8
def user
@user
end
|
#voting ⇒ Object
Returns the value of attribute voting.
7
8
9
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 7
def voting
@voting
end
|
Class Method Details
.find(id) ⇒ Object
65
66
67
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 65
def self.find(id)
return CommentService.new.find_by_id(id)
end
|
.newest(pages = 1) ⇒ Object
55
56
57
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 55
def self.newest(pages = 1)
return CommentService.new.(pages)
end
|
59
60
61
62
63
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 59
def self.(pages = 1, url = nil)
args = [pages]
args << url unless url.nil?
return CommentService.new. *args
end
|
Instance Method Details
#<<(comment) ⇒ Object
38
39
40
41
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 38
def <<()
.parent = self
@children <<
end
|
#<=>(other_comment) ⇒ Object
47
48
49
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 47
def <=>()
return .voting.score <=> @voting.score
end
|
#downvote ⇒ Object
79
80
81
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 79
def downvote
VotingService.new.vote(@voting.downvote)
end
|
#each(&block) ⇒ Object
43
44
45
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 43
def each(&block)
@children.each(&block)
end
|
#id ⇒ Object
22
23
24
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 22
def id
return @absolute_link.split("=")[1].to_i
end
|
#parent_id ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 26
def parent_id
if parent
parent.id
elsif @parent_link
@parent_link[/\d+/].to_i
end
end
|
#reply(text) ⇒ Object
69
70
71
72
73
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 69
def reply(text)
return false unless @reply_link
CommentService.new.(@reply_link, text)
return true
end
|
#text ⇒ Object
34
35
36
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 34
def text
@text ||= text_html.gsub(/<.{1,2}>/, "")
end
|
#upvote ⇒ Object
75
76
77
|
# File 'lib/ruby-hackernews/domain/comment/comment.rb', line 75
def upvote
VotingService.new.vote(@voting.upvote)
end
|