Class: Fourchan::Kit::Thread
- Inherits:
-
Object
- Object
- Fourchan::Kit::Thread
- Defined in:
- lib/fourchan/kit/thread.rb
Overview
Thread is used to deal with a thread from a board.
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#fetch_replies ⇒ Object
Get all replies from the thread.
-
#images ⇒ Object
Returns an array of image URLs from the thread (see Fourgem::Post#image_link).
-
#initialize(board, thread) ⇒ Thread
constructor
A new instance of Thread.
-
#op ⇒ Object
Return only the first post from the thread.
-
#posts ⇒ Object
Returns all posts from the thread, including OP.
-
#replies ⇒ Object
Return all the replies.
Constructor Details
#initialize(board, thread) ⇒ Thread
Returns a new instance of Thread.
9 10 11 12 13 |
# File 'lib/fourchan/kit/thread.rb', line 9 def initialize(board, thread) @posts = [] @board = board @thread = API.get_thread(board, thread) end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
7 8 9 |
# File 'lib/fourchan/kit/thread.rb', line 7 def board @board end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
7 8 9 |
# File 'lib/fourchan/kit/thread.rb', line 7 def thread @thread end |
Instance Method Details
#fetch_replies ⇒ Object
Get all replies from the thread. OP is not included.
It then returns the replies.
35 36 37 38 39 |
# File 'lib/fourchan/kit/thread.rb', line 35 def fetch_replies @posts = [] @thread = API.get_thread(@board, self.op.no) self.replies end |
#images ⇒ Object
Returns an array of image URLs from the thread (see Fourgem::Post#image_link).
49 50 51 52 53 54 55 |
# File 'lib/fourchan/kit/thread.rb', line 49 def images images = [] self.posts.each do |post| images << post.image_link end images.compact end |
#op ⇒ Object
Return only the first post from the thread.
28 29 30 |
# File 'lib/fourchan/kit/thread.rb', line 28 def op self.posts[0] end |
#posts ⇒ Object
Returns all posts from the thread, including OP.
17 18 19 20 21 22 23 24 |
# File 'lib/fourchan/kit/thread.rb', line 17 def posts if @posts.empty? @thread.each do |post| @posts << Post.new(post, @board) end end @posts end |
#replies ⇒ Object
Return all the replies. OP is not included.
43 44 45 |
# File 'lib/fourchan/kit/thread.rb', line 43 def replies self.posts[1..-1] end |