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
-
#board ⇒ Object
(also: #catalog)
readonly
Returns the value of attribute board.
Instance Method Summary collapse
-
#all_posts ⇒ Array
Returns all posts for the entire board.
-
#all_threads ⇒ Array
Returns all threads, but not its replies, for the entire board.
-
#initialize(board) ⇒ Board
constructor
A new instance of Board.
-
#posts(page = 1) ⇒ Array
Returns all the posts from the threads on a page.
-
#threads(page = 1) ⇒ Array
Returns only the first post (OP) from the threads on a page.
Constructor Details
#initialize(board) ⇒ 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
#board ⇒ Object (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
#all_posts ⇒ Array
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 |
#all_threads ⇒ Array
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 |