Class: Wikidotrb::Module::ForumPostCollection
- Inherits:
-
Array
- Object
- Array
- Wikidotrb::Module::ForumPostCollection
- Defined in:
- lib/wikidotrb/module/forum_post.rb
Instance Attribute Summary collapse
-
#thread
Returns the value of attribute thread.
Class Method Summary collapse
-
.acquire_parent_post(thread:, posts:) ⇒ Array<ForumPost>
Retrieve and set parent post.
-
.acquire_post_info(thread:, posts:) ⇒ Array<ForumPost>
Retrieve and set post information.
Instance Method Summary collapse
-
#find(target_id) ⇒ ForumPost?
Search for a post by ID.
-
#get_parent_post
Retrieve parent post for revisions.
-
#get_post_info
Retrieve post information for revisions.
-
#initialize(thread:, posts: []) ⇒ ForumPostCollection
constructor
Initialization method.
Constructor Details
#initialize(thread:, posts: []) ⇒ ForumPostCollection
Initialization method
15 16 17 18 |
# File 'lib/wikidotrb/module/forum_post.rb', line 15 def initialize(thread:, posts: []) super(posts) @thread = thread end |
Instance Attribute Details
#thread
Returns the value of attribute thread.
10 11 12 |
# File 'lib/wikidotrb/module/forum_post.rb', line 10 def thread @thread end |
Class Method Details
.acquire_parent_post(thread:, posts:) ⇒ Array<ForumPost>
Retrieve and set parent post
31 32 33 34 35 36 |
# File 'lib/wikidotrb/module/forum_post.rb', line 31 def self.acquire_parent_post(thread:, posts:) return posts if posts.empty? posts.each { |post| post.parent = thread.get(post.parent_id) } posts end |
.acquire_post_info(thread:, posts:) ⇒ Array<ForumPost>
Retrieve and set post information
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/wikidotrb/module/forum_post.rb', line 47 def self.acquire_post_info(thread:, posts:) return posts if posts.empty? responses = thread.site.amc_request( bodies: posts.map do |post| { "postId" => post.id, "threadId" => thread.id, "moduleName" => "forum/sub/ForumEditPostFormModule" } end ) responses.each_with_index do |response, index| html = Nokogiri::HTML(response.body.to_s) title = html.at_css("input#np-title")&.text&.strip source = html.at_css("textarea#np-text")&.text&.strip posts[index].title = title posts[index].source = source end posts end |
Instance Method Details
#find(target_id) ⇒ ForumPost?
Search for a post by ID
23 24 25 |
# File 'lib/wikidotrb/module/forum_post.rb', line 23 def find(target_id) find { |post| post.id == target_id } end |
#get_parent_post
Retrieve parent post for revisions
39 40 41 |
# File 'lib/wikidotrb/module/forum_post.rb', line 39 def get_parent_post ForumPostCollection.acquire_parent_post(thread: @thread, posts: self) end |
#get_post_info
Retrieve post information for revisions
72 73 74 |
# File 'lib/wikidotrb/module/forum_post.rb', line 72 def get_post_info ForumPostCollection.acquire_post_info(thread: @thread, posts: self) end |