Class: Fourchan::Kit::Board
- Inherits:
-
Object
- Object
- Fourchan::Kit::Board
- Defined in:
- lib/fourchan/kit/board.rb
Overview
Board is used to deal with a 4chan board.
Instance Attribute Summary (collapse)
-
- (Object) board
(also: #catalog)
readonly
Returns the value of attribute board.
Instance Method Summary (collapse)
-
- (Array) all_posts
Returns all posts for the entire board.
-
- (Array) all_threads
Returns all threads, but not its replies, for the entire board.
-
- (Board) initialize(board)
constructor
A new instance of Board.
-
- (Array) posts(page = 1)
Returns all the posts from the threads on a page.
-
- (Array) threads(page = 1)
Returns only the first post (OP) from the threads on a page.
Constructor Details
- (Board) initialize(board)
Returns a new instance of Board
9 10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
- (Object) board (readonly) Also known as: catalog
Returns the value of attribute board
7 8 9 |
# File 'lib/fourchan/kit/board.rb', line 7 def board @board end |
Instance Method Details
- (Array) all_posts
Returns all posts for the entire board.
Note: This method is pretty slow. Just wait for it to finish.
63 64 65 66 67 68 69 |
# 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 |
- (Array) all_threads
Returns all threads, but not its replies, for the entire board.
35 36 37 38 39 40 41 |
# 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 |
- (Array) posts(page = 1)
Returns all the posts from the threads on a page.
48 49 50 51 52 53 54 55 56 |
# 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 |
- (Array) threads(page = 1)
Returns only the first post (OP) from the threads on a page.
23 24 25 26 27 28 29 |
# 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 |