Class: NeonRAW::Objects::Comment
- Includes:
- Thing::Createable, Thing::Editable, Thing::Gildable, Thing::Inboxable, Thing::Moderateable, Thing::Refreshable, Thing::Repliable, Thing::Saveable, Thing::Votable
- Defined in:
- lib/NeonRAW/objects/comment.rb
Overview
The comment object.
Instance Attribute Summary collapse
-
#approved_by ⇒ String?
readonly
Returns which mod approved the comment or nil if none did or you aren’t a moderator of that subreddit.
-
#archived? ⇒ Boolean
readonly
Returns whether or not the comment is archived.
-
#author ⇒ String
readonly
Returns the author of the comment.
-
#author_flair_css_class ⇒ String?
readonly
Returns the author’s flair CSS class or nil if there is none.
-
#author_flair_text ⇒ String?
readonly
Returns the author’s flair text or nil if there is none.
-
#body ⇒ String?
readonly
Returns the text body of the comment or nil if there isn’t one.
-
#body_html ⇒ String?
readonly
Returns the text body of the comment with HTML or nil if there isn’t one.
-
#gold_count ⇒ Integer
readonly
Returns the amount of gold a comment has been given.
-
#link_author ⇒ String
readonly
Returns the author of the submission link that the comment was made in response to.
-
#link_name ⇒ String
readonly
Returns the name of the link that this comment is in.
-
#link_title ⇒ String
readonly
Returns the title of the parent link.
-
#link_url ⇒ String
readonly
Returns the URL of the parent link.
-
#num_reports ⇒ Integer?
readonly
Returns the number of times the comment has been reported or nil if it hasn’t or you aren’t a moderator.
-
#parent_name ⇒ String
readonly
Returns the name of either the link or the comment that this comment is a reply to.
-
#removed_by ⇒ String?
readonly
Returns which mod removed the comment or nil if none did or you aren’t a moderator of that subreddit.
-
#saved? ⇒ Boolean
readonly
Returns whether or not you saved the comment.
-
#score ⇒ Integer
readonly
Returns the karma score of the comment.
-
#score_hidden? ⇒ Boolean
readonly
Returns whether or not the karma score of the comment is hidden.
-
#subreddit ⇒ String
readonly
Returns the subreddit the comment was posted to.
-
#subreddit_id ⇒ String
readonly
Returns the ID of the subreddit where the comment was posted to.
Attributes included from Thing::Votable
Attributes included from Thing::Moderateable
Attributes inherited from Thing
Instance Method Summary collapse
-
#comment? ⇒ Boolean
Checks whether or not this is a comment.
-
#initialize(client, data) ⇒ Comment
constructor
A new instance of Comment.
-
#morecomments? ⇒ Boolean
Returns whether or not the comment is a MoreComments object.
-
#permalink ⇒ String
Creates the comment’s permalink.
-
#replies ⇒ Array<NeonRAW::Objects::Comment, NeonRAW::Objects::MoreComments>?
Gets the replies made to the comment.
-
#replies? ⇒ Boolean
Checks whether or not the comment has replies to it.
-
#submission? ⇒ Boolean
Checks whether or not this is a submission.
Methods included from Thing::Votable
#clear_vote, #downvote, #downvoted?, #upvote, #upvoted?, #voted?
Methods included from Thing::Saveable
Methods included from Thing::Repliable
Methods included from Thing::Refreshable
Methods included from Thing::Moderateable
#approve!, #distinguish!, #distinguished?, #distinguished_by, #ignore_reports!, #remove!, #report, #spam!, #stickied?, #unignore_reports!
Methods included from Thing::Inboxable
#mark_as_read, #mark_as_unread, #reply
Methods included from Thing::Gildable
Methods included from Thing::Editable
#delete!, #edit!, #edited?, #last_edit
Methods included from Thing::Createable
Constructor Details
#initialize(client, data) ⇒ Comment
Returns a new instance of Comment.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/NeonRAW/objects/comment.rb', line 81 def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end |
Instance Attribute Details
#approved_by ⇒ String? (readonly)
Returns which mod approved the comment or nil if none did or you aren’t a moderator of that subreddit.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#archived? ⇒ Boolean (readonly)
Returns whether or not the comment is archived.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#author ⇒ String (readonly)
Returns the author of the comment.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#author_flair_css_class ⇒ String? (readonly)
Returns the author’s flair CSS class or nil if there is none.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#author_flair_text ⇒ String? (readonly)
Returns the author’s flair text or nil if there is none.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#body ⇒ String? (readonly)
Returns the text body of the comment or nil if there isn’t one.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#body_html ⇒ String? (readonly)
Returns the text body of the comment with HTML or nil if there isn’t one.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#gold_count ⇒ Integer (readonly)
Returns the amount of gold a comment has been given.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#link_author ⇒ String (readonly)
This attribute only exists if the comment is fetched from outside the thread it was posted in (so like user pages, /r/subreddit/comments, that type of stuff).
Returns the author of the submission link that the comment was made in response to.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#link_name ⇒ String (readonly)
Returns the name of the link that this comment is in.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#link_title ⇒ String (readonly)
This attribute only exists if the comment is fetched from outside the thread it was posted in (so like user pages, /r/subreddit/comments, that type of stuff).
Returns the title of the parent link.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#link_url ⇒ String (readonly)
This attribute only exists if the comment is fetched from outside the thread it was posted in (so like user pages, /r/subreddit/comments, that type of stuff).
Returns the URL of the parent link.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#num_reports ⇒ Integer? (readonly)
Returns the number of times the comment has been reported or nil if it hasn’t or you aren’t a moderator.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#parent_name ⇒ String (readonly)
Returns the name of either the link or the comment that this comment is a reply to.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#removed_by ⇒ String? (readonly)
Returns which mod removed the comment or nil if none did or you aren’t a moderator of that subreddit.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#saved? ⇒ Boolean (readonly)
Returns whether or not you saved the comment.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#score ⇒ Integer (readonly)
Returns the karma score of the comment.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#score_hidden? ⇒ Boolean (readonly)
Returns whether or not the karma score of the comment is hidden.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#subreddit ⇒ String (readonly)
Returns the subreddit the comment was posted to.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
#subreddit_id ⇒ String (readonly)
Returns the ID of the subreddit where the comment was posted to.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/NeonRAW/objects/comment.rb', line 66 class Comment < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Inboxable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The comment data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) instance_variable_set(:"@#{key}", value) next if %i[created created_utc replies].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :removed_by, :banned_by alias_method :gold_count, :gilded alias_method :saved?, :saved alias_method :score_hidden?, :score_hidden alias_method :archived?, :archived alias_method :link_name, :link_id alias_method :parent_name, :parent_id end end # Returns whether or not the comment is a MoreComments object. # @!method morecomments? # @return [Boolean] Returns false. def morecomments? false end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns false. def submission? false end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns true. def comment? true end # Checks whether or not the comment has replies to it. # @!method replies? # @return [Boolean] Returns whether or not the comment has replies to it. def replies? if @replies.nil? false else true end end # Gets the replies made to the comment. # @!method replies # @return [Array<NeonRAW::Objects::Comment, # NeonRAW::Objects::MoreComments>, nil] Returns either a list of the # Comments/MoreComments or nil if there were no replies. def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end # Creates the comment's permalink. # @!method permalink # @return [String] Returns the comment's permalink. def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end end |
Instance Method Details
#comment? ⇒ Boolean
Checks whether or not this is a comment.
120 121 122 |
# File 'lib/NeonRAW/objects/comment.rb', line 120 def comment? true end |
#morecomments? ⇒ Boolean
Returns whether or not the comment is a MoreComments object.
106 107 108 |
# File 'lib/NeonRAW/objects/comment.rb', line 106 def morecomments? false end |
#permalink ⇒ String
Creates the comment’s permalink.
156 157 158 159 160 |
# File 'lib/NeonRAW/objects/comment.rb', line 156 def permalink submission_id = link_id[3..-1] # trims the t3_ from the fullname # the // is intentional "https://www.reddit.com/r/#{subreddit}/comments/#{submission_id}//#{id}" end |
#replies ⇒ Array<NeonRAW::Objects::Comment, NeonRAW::Objects::MoreComments>?
Gets the replies made to the comment.
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/NeonRAW/objects/comment.rb', line 140 def replies return nil if @replies.nil? comments = [] @replies[:data][:children].each do |reply| if reply[:kind] == 't1' comments << Comment.new(@client, reply[:data]) elsif reply[:kind] == 'more' comments << MoreComments.new(@client, reply[:data]) end end comments end |
#replies? ⇒ Boolean
Checks whether or not the comment has replies to it.
127 128 129 130 131 132 133 |
# File 'lib/NeonRAW/objects/comment.rb', line 127 def replies? if @replies.nil? false else true end end |
#submission? ⇒ Boolean
Checks whether or not this is a submission.
113 114 115 |
# File 'lib/NeonRAW/objects/comment.rb', line 113 def submission? false end |