Class: Trefoil::Post
- Inherits:
-
Object
- Object
- Trefoil::Post
- Defined in:
- lib/trefoil/post.rb
Overview
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)
Instance Method Summary collapse
-
#[](key) ⇒ Hash, ...
Access underlying post data with symbolized names Possible fields are available for viewing in the (API documentation).
-
#image? ⇒ true, false
Whether this post has an image associated with it.
-
#image_url ⇒ Image?
Url to the image of this post, if any.
-
#initialize(client, board, thread, data) ⇒ Post
constructor
Intended for internal use.
-
#op ⇒ Post
The OP to the thread this post is in.
-
#op? ⇒ true, false
Whether this is the first post in a thread.
-
#url ⇒ String
Url to this post.
Constructor Details
#initialize(client, board, thread, data) ⇒ Post
Intended for internal use
9 10 11 12 13 14 |
# File 'lib/trefoil/post.rb', line 9 def initialize(client, board, thread, data) @client = client @board = board @thread = thread @data = data end |
Instance Method Details
#[](key) ⇒ Hash, ...
Access underlying post data with symbolized names Possible fields are available for viewing in the (API documentation)
20 21 22 |
# File 'lib/trefoil/post.rb', line 20 def [](key) @data[key] end |
#image? ⇒ true, false
Whether this post has an image associated with it
32 33 34 |
# File 'lib/trefoil/post.rb', line 32 def image? !@data[:filename].is_nil? end |
#image_url ⇒ Image?
Url to the image of this post, if any.
38 39 40 41 42 |
# File 'lib/trefoil/post.rb', line 38 def image_url return nil unless image? Image.new(@data) end |
#op ⇒ Post
The OP to the thread this post is in.
58 59 60 61 62 63 64 |
# File 'lib/trefoil/post.rb', line 58 def op if @data[:resto].zero self else thread.posts[0] end end |
#op? ⇒ true, false
Whether this is the first post in a thread. All op’s has a resto of 0
26 27 28 |
# File 'lib/trefoil/post.rb', line 26 def op? @data[:resto].zero? end |
#url ⇒ String
Url to this post
46 47 48 49 50 51 52 53 54 |
# 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 |