class Trefoil::Post
Represents a `post` object. Post
object data varies greatly based on board, content, and whether it is an OP. Possible fields are available for viewing in the (API documentation)
Public Class Methods
new(client, board, thread, data)
click to toggle source
Intended for internal use
# File lib/trefoil/post.rb, line 9 def initialize(client, board, thread, data) @client = client @board = board @thread = thread @data = data end
Public Instance Methods
[](key)
click to toggle source
Access underlying post data with symbolized names Possible fields are available for viewing in the (API documentation) @param key [Symbol] The API field @return [Hash, Array, String, Fixnum]
# File lib/trefoil/post.rb, line 20 def [](key) @data[key] end
image()
click to toggle source
image?()
click to toggle source
Whether this post has an image associated with it @return [true, false]
# File lib/trefoil/post.rb, line 32 def image? !@data[:filename].nil? end
op()
click to toggle source
The OP to the thread this post is in. @return [Post] A post object for the OP, the instance it was called on if it is the OP.
# File lib/trefoil/post.rb, line 58 def op if @data[:resto].zero self else thread.posts[0] end end
op?()
click to toggle source
Whether this is the first post in a thread. All op's has a resto of 0 @return [true, false]
# File lib/trefoil/post.rb, line 26 def op? @data[:resto].zero? end
url()
click to toggle source
Url to this post @return [String] The url to this post.
# File lib/trefoil/post.rb, line 46 def url direct_link = if @data[:resto].zero? @data[:no] else "#{@data[:resto]}p##{@data[:no]}" end "http://boards.4chan.org/#{@board}/thread/#{direct_link}" end