class Trefoil::Image
A class representing an Image
using data from a post object.
Attributes
@return [String] The name of the board this image is associated with.
@return [String] File extension of the fullsize image.
@return [0, 1, nil] Whether this image is deleted. Use `#image?` for a boolean representation.
@return [String] Original filename of this image
@return [Integer] Filesize of the fullsize image.
@return [Integer] Height of fullsize image.
@return [String] MD5 hash of fullsize image.
@return [0, 1, nil] Whether this image is a spoiler. Use `#spoiler?` for a boolean representation.
@return [Integer] Renamed filename (UNIX timestamp + miliseconds)
@return [Integer] Height of thumbnail.
@return [Integer] Width of thumbnail.
@return [Integer] Width of fullsize image.
Public Class Methods
Create a new image object. Intended for internal use. @param data [Hash<Symbol => Integer, String] Data from a post object to extrapolate info from. @param board [Board, String] The board, or board name, associated with the post this image is from.
# File lib/trefoil/image.rb, line 47 def initialize(data, board) expand_data(data) @board_name = board.is_a?(Board) ? board[:name] : board end
Public Instance Methods
Convenience abstraction for determining if this file was deleted. @return [true, false] Whether this file was deleted.
# File lib/trefoil/image.rb, line 66 def file_deleted? filedeleted == 1 end
Convenience abstraction for determining if this file is a spoiler. @return [true, false] Whether this file is a spoiler.
# File lib/trefoil/image.rb, line 72 def spoiler? spoiler == 1 end
The url to the thumbnail of this image. @return [String] url to the thumbnail of this image.
# File lib/trefoil/image.rb, line 60 def thumbnail_url "http://i.4cdn.org/#{board_name}/#{tim}s.jpg" end
The url to the full size image. @return [String] url to the fullsize version of this image.
# File lib/trefoil/image.rb, line 54 def url "http://i.4cdn.org/#{board_name}/#{tim}#{ext}" end
Private Instance Methods
Move desired values from post data into instance variables. @param data [Hash<Symbol => Integer, String] Data from a Post
object.
# File lib/trefoil/image.rb, line 80 def expand_data(data) %i[tim filename ext fsize md5 w h tn_w tn_h filedeleted spoiler].each do |sym| instance_variable_set("@#{sym}", data[sym]) end end