Class: RedditKit::Comment
- Defined in:
- lib/redditkit/comment.rb
Overview
A class representing a comment.
Instance Attribute Summary collapse
-
#approved_by ⇒ Object
readonly
Returns the value of attribute approved_by.
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#author_flair_css_class ⇒ Object
readonly
Returns the value of attribute author_flair_css_class.
-
#author_flair_text ⇒ Object
readonly
Returns the value of attribute author_flair_text.
-
#author_id ⇒ Object
readonly
Returns the value of attribute author_id.
-
#banned_by ⇒ Object
readonly
Returns the value of attribute banned_by.
-
#body ⇒ Object
(also: #text)
readonly
Returns the value of attribute body.
-
#body_html ⇒ Object
readonly
Returns the value of attribute body_html.
-
#distinguished ⇒ Object
readonly
Returns the value of attribute distinguished.
-
#edited ⇒ Object
readonly
Returns the value of attribute edited.
-
#gilded ⇒ Object
readonly
Returns the value of attribute gilded.
-
#link_id ⇒ Object
readonly
Returns the value of attribute link_id.
-
#num_reports ⇒ Object
readonly
Returns the value of attribute num_reports.
-
#score_hidden ⇒ Object
readonly
Returns the value of attribute score_hidden.
-
#subreddit ⇒ Object
readonly
Returns the value of attribute subreddit.
-
#subreddit_id ⇒ Object
readonly
Returns the value of attribute subreddit_id.
Attributes inherited from Thing
Attributes inherited from Base
Instance Method Summary collapse
-
#deleted? ⇒ Boolean
Whether a comment has been deleted by its submitter or a moderator.
-
#replies ⇒ Object
The replies to a comment.
-
#replies? ⇒ Boolean
Whether the comment has any replies.
Methods included from Votable
#downvoted?, #downvotes, #score, #upvoted?, #upvotes, #voted?
Methods included from Creatable
Methods inherited from Thing
Methods inherited from Base
Constructor Details
This class inherits a constructor from RedditKit::Base
Instance Attribute Details
#approved_by ⇒ Object (readonly)
Returns the value of attribute approved_by.
12 13 14 |
# File 'lib/redditkit/comment.rb', line 12 def approved_by @approved_by end |
#author ⇒ Object (readonly)
Returns the value of attribute author.
13 14 15 |
# File 'lib/redditkit/comment.rb', line 13 def @author end |
#author_flair_css_class ⇒ Object (readonly)
Returns the value of attribute author_flair_css_class.
14 15 16 |
# File 'lib/redditkit/comment.rb', line 14 def @author_flair_css_class end |
#author_flair_text ⇒ Object (readonly)
Returns the value of attribute author_flair_text.
15 16 17 |
# File 'lib/redditkit/comment.rb', line 15 def @author_flair_text end |
#author_id ⇒ Object (readonly)
Returns the value of attribute author_id.
16 17 18 |
# File 'lib/redditkit/comment.rb', line 16 def @author_id end |
#banned_by ⇒ Object (readonly)
Returns the value of attribute banned_by.
17 18 19 |
# File 'lib/redditkit/comment.rb', line 17 def banned_by @banned_by end |
#body ⇒ Object (readonly) Also known as: text
Returns the value of attribute body.
18 19 20 |
# File 'lib/redditkit/comment.rb', line 18 def body @body end |
#body_html ⇒ Object (readonly)
Returns the value of attribute body_html.
19 20 21 |
# File 'lib/redditkit/comment.rb', line 19 def body_html @body_html end |
#distinguished ⇒ Object (readonly)
Returns the value of attribute distinguished.
20 21 22 |
# File 'lib/redditkit/comment.rb', line 20 def distinguished @distinguished end |
#edited ⇒ Object (readonly)
Returns the value of attribute edited.
21 22 23 |
# File 'lib/redditkit/comment.rb', line 21 def edited @edited end |
#gilded ⇒ Object (readonly)
Returns the value of attribute gilded.
22 23 24 |
# File 'lib/redditkit/comment.rb', line 22 def gilded @gilded end |
#link_id ⇒ Object (readonly)
Returns the value of attribute link_id.
23 24 25 |
# File 'lib/redditkit/comment.rb', line 23 def link_id @link_id end |
#num_reports ⇒ Object (readonly)
Returns the value of attribute num_reports.
24 25 26 |
# File 'lib/redditkit/comment.rb', line 24 def num_reports @num_reports end |
#score_hidden ⇒ Object (readonly)
Returns the value of attribute score_hidden.
25 26 27 |
# File 'lib/redditkit/comment.rb', line 25 def score_hidden @score_hidden end |
#subreddit ⇒ Object (readonly)
Returns the value of attribute subreddit.
26 27 28 |
# File 'lib/redditkit/comment.rb', line 26 def subreddit @subreddit end |
#subreddit_id ⇒ Object (readonly)
Returns the value of attribute subreddit_id.
27 28 29 |
# File 'lib/redditkit/comment.rb', line 27 def subreddit_id @subreddit_id end |
Instance Method Details
#deleted? ⇒ Boolean
Whether a comment has been deleted by its submitter or a moderator.
33 34 35 |
# File 'lib/redditkit/comment.rb', line 33 def deleted? == '[deleted]' and body == '[deleted]' end |
#replies ⇒ Object
The replies to a comment.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/redditkit/comment.rb', line 38 def replies replies_listing = @attributes[:replies] return [] if replies_listing.blank? replies_array = replies_listing[:data][:children] @comment_objects ||= replies_array.map do |comment| RedditKit::Comment.new(comment) end end |
#replies? ⇒ Boolean
Whether the comment has any replies.
50 51 52 |
# File 'lib/redditkit/comment.rb', line 50 def replies? !replies.empty? end |