ruqqus 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,61 +0,0 @@
1
- require_relative 'submission'
2
-
3
- module Ruqqus
4
-
5
- ##
6
- # Describes a comment in a post.
7
- class Comment < Submission
8
-
9
- ##
10
- # Captures the ID of a comment from a Ruqqus URL
11
- COMMENT_REGEX = /ruqqus.com\/post\/.+\/.+\/([A-Za-z0-9]+)\/?/.freeze
12
-
13
- ##
14
- # @return [Integer] the level of "nesting" in the comment tree, starting at `1` when in direct reply to the post.
15
- def level
16
- @data[:level]
17
- end
18
-
19
- ##
20
- # @return [String] the unique ID of the parent for this comment.
21
- def parent_id
22
- @data[:parent]
23
- end
24
-
25
- ##
26
- # @return [Post,Comment] the parent for this content.
27
- def parent
28
- #noinspection RubyYardReturnMatch
29
- @parent ||= level > 1 ? Ruqqus.comment(parent_id) : Ruqqus.post(parent_id)
30
- end
31
-
32
- ##
33
- # @return [String] the ID of the post this comment belongs to.
34
- def post_id
35
- @data[:post]
36
- end
37
-
38
- ##
39
- # @return [Post] the post this comment belongs to.
40
- def post
41
- #noinspection RubyYardReturnMatch
42
- Ruqqus.post(post_id)
43
- end
44
-
45
- ##
46
- # Creates a new {Comment} instance from the specified URL.
47
- #
48
- # @param url [String] a URL link to a comment.
49
- #
50
- # @return [Comment] the {Comment} instance the URL links to.
51
- #
52
- # @raise [ArgumentError] then `url` is `nil`.
53
- # @raise [Ruqqus::Error] when the link is not for a Ruqqus comment.
54
- def self.from_url(url)
55
- raise(ArgumentError, 'url cannot be nil') unless url
56
- match = COMMENT_REGEX.match(url)
57
- raise(ArgumentError, 'invalid URL for a comment') unless match
58
- Ruqqus.comment($1)
59
- end
60
- end
61
- end