Class: RedditKit::Comment

Inherits:
Thing show all
Includes:
Creatable, Votable
Defined in:
lib/redditkit/comment.rb

Overview

A class representing a comment.

Instance Attribute Summary collapse

Attributes inherited from Thing

#id, #kind

Attributes inherited from Base

#attributes

Instance Method Summary collapse

Methods included from Votable

#downvoted?, #downvotes, #score, #upvoted?, #upvotes, #voted?

Methods included from Creatable

#created_at

Methods inherited from Thing

#==, #full_name

Methods inherited from Base

#[], attr_reader, #initialize

Constructor Details

This class inherits a constructor from RedditKit::Base

Instance Attribute Details

#approved_byObject (readonly)

Returns the value of attribute approved_by.



12
13
14
# File 'lib/redditkit/comment.rb', line 12

def approved_by
  @approved_by
end

#authorObject (readonly)

Returns the value of attribute author.



13
14
15
# File 'lib/redditkit/comment.rb', line 13

def author
  @author
end

#author_flair_css_classObject (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
  @author_flair_css_class
end

#author_flair_textObject (readonly)

Returns the value of attribute author_flair_text.



15
16
17
# File 'lib/redditkit/comment.rb', line 15

def author_flair_text
  @author_flair_text
end

#author_idObject (readonly)

Returns the value of attribute author_id.



16
17
18
# File 'lib/redditkit/comment.rb', line 16

def author_id
  @author_id
end

#banned_byObject (readonly)

Returns the value of attribute banned_by.



17
18
19
# File 'lib/redditkit/comment.rb', line 17

def banned_by
  @banned_by
end

#bodyObject (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_htmlObject (readonly)

Returns the value of attribute body_html.



19
20
21
# File 'lib/redditkit/comment.rb', line 19

def body_html
  @body_html
end

#distinguishedObject (readonly)

Returns the value of attribute distinguished.



20
21
22
# File 'lib/redditkit/comment.rb', line 20

def distinguished
  @distinguished
end

#editedObject (readonly)

Returns the value of attribute edited.



21
22
23
# File 'lib/redditkit/comment.rb', line 21

def edited
  @edited
end

#gildedObject (readonly)

Returns the value of attribute gilded.



22
23
24
# File 'lib/redditkit/comment.rb', line 22

def gilded
  @gilded
end

Returns the value of attribute link_id.



23
24
25
# File 'lib/redditkit/comment.rb', line 23

def link_id
  @link_id
end

#num_reportsObject (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_hiddenObject (readonly)

Returns the value of attribute score_hidden.



25
26
27
# File 'lib/redditkit/comment.rb', line 25

def score_hidden
  @score_hidden
end

#subredditObject (readonly)

Returns the value of attribute subreddit.



26
27
28
# File 'lib/redditkit/comment.rb', line 26

def subreddit
  @subreddit
end

#subreddit_idObject (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.

Returns:

  • (Boolean)


33
34
35
# File 'lib/redditkit/comment.rb', line 33

def deleted?
  author == '[deleted]' and body == '[deleted]'
end

#repliesObject

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.

Returns:

  • (Boolean)


50
51
52
# File 'lib/redditkit/comment.rb', line 50

def replies?
  !replies.empty?
end