class Trefoil::Thread
Represents an array of Post
objects with additional convenience methods
Public Class Methods
new(client, board, id)
click to toggle source
# File lib/trefoil/thread.rb, line 6 def initialize(client, board, id) @client = client @board = board @id = id @posts = nil end
Public Instance Methods
[](index)
click to toggle source
Get a post based on its position @param index [Integer] the index of the desired post @return [Post, nil] A post object or nil if out of bounds.
# File lib/trefoil/thread.rb, line 16 def [](index) posts[index] end
op()
click to toggle source
Convenience method to get the first post in a thread @return [Post]
# File lib/trefoil/thread.rb, line 29 def op posts[0] end
posts()
click to toggle source
An array of all posts in the thread @return [Array<Post>] All posts in this thread since last update
# File lib/trefoil/thread.rb, line 22 def posts fetch_posts if @posts.nil? @posts end
update()
click to toggle source
Refresh post list
# File lib/trefoil/thread.rb, line 34 def update fetch_posts end
Private Instance Methods
fetch_posts()
click to toggle source
Fetch all posts into
# File lib/trefoil/thread.rb, line 41 def fetch_posts @posts = [] @client.get("/#{@board.name}/thread/#{@id}.json")[:posts].each do |post| @posts << Post.new(@client, @board, self, post) end end