class Fourchan::Kit::Board

Board is used to deal with a 4chan board.

Attributes

board[R]
catalog[R]

Public Class Methods

new(board) click to toggle source
# File lib/fourchan/kit/board.rb, line 9
def initialize(board)
  if Kit.fourchan_boards.include?(board)
    @name  = board
    @board = API.get_catalog(board)
  else
    raise "Not a valid board."
  end
end

Public Instance Methods

all_posts() click to toggle source

Returns all posts for the entire board.

Note: This method is pretty slow. Just wait for it to finish.

@return [Array]

# File lib/fourchan/kit/board.rb, line 63
def all_posts
  posts = []
  @board.each_with_index do |_, i|
    posts << posts(i + 1)
  end
  posts.flatten
end
all_threads() click to toggle source

Returns all threads, but not its replies, for the entire board.

@return [Array]

# File lib/fourchan/kit/board.rb, line 35
def all_threads
  all_threads = []
  @board.each do |page|
    all_threads << threads(page["page"])
  end
  all_threads.flatten
end
posts(page = 1) click to toggle source

Returns all the posts from the threads on a page.

@param page [Integer] the page to get threads from. @return [Array]

# File lib/fourchan/kit/board.rb, line 48
def posts(page = 1)
  posts   = []
  threads = threads(page)
  threads.each do |t|
    thread = Thread.new(@name, t.no)
    posts << thread.posts
  end
  posts.flatten
end
threads(page = 1) click to toggle source

Returns only the first post (OP) from the threads on a page.

@param page [Integer] the page to get threads from. @return [Array]

# File lib/fourchan/kit/board.rb, line 23
def threads(page = 1)
  threads = []
  @board[page - 1]["threads"].each do |thread|
    threads << Post.new(thread, @name)
  end
  threads
end