Class: Fourchan::Kit::Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/fourchan/kit/thread.rb

Overview

Thread is used to deal with a thread from a board.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Thread) initialize(board, 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

- (Object) board (readonly)

Returns the value of attribute board



7
8
9
# File 'lib/fourchan/kit/thread.rb', line 7

def board
  @board
end

- (Object) thread (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

- (Object) fetch_replies

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

- (Object) images

Returns an array of image URLs from the thread (see 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

- (Object) op

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

- (Object) posts

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

- (Object) replies

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