class Trefoil::Image

A class representing an Image using data from a post object.

Attributes

board_name[R]

@return [String] The name of the board this image is associated with.

ext[R]

@return [String] File extension of the fullsize image.

filedeleted[R]

@return [0, 1, nil] Whether this image is deleted. Use `#image?` for a boolean representation.

filename[R]

@return [String] Original filename of this image

fsize[R]

@return [Integer] Filesize of the fullsize image.

h[R]

@return [Integer] Height of fullsize image.

md5[R]

@return [String] MD5 hash of fullsize image.

spoiler[R]

@return [0, 1, nil] Whether this image is a spoiler. Use `#spoiler?` for a boolean representation.

tim[R]

@return [Integer] Renamed filename (UNIX timestamp + miliseconds)

tn_h[R]

@return [Integer] Height of thumbnail.

tn_w[R]

@return [Integer] Width of thumbnail.

w[R]

@return [Integer] Width of fullsize image.

Public Class Methods

new(data, board) click to toggle source

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

file_deleted?() click to toggle source

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
spoiler?() click to toggle source

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
thumbnail_url() click to toggle source

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
url() click to toggle source

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

expand_data(data) click to toggle source

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