class Fourchanify::Image

Attributes

board[RW]
directory_name[RW]
ext[RW]
filename[RW]
fsize[RW]
tim[RW]
url[RW]

Public Class Methods

prepare(attributes) click to toggle source
# File lib/fourchanify/models/image.rb, line 5
def self.prepare(attributes)
  image = Image.new
  image.filename = attributes[:filename]
  image.ext = attributes[:ext]
  image.fsize = attributes[:fsize]
  image.tim = attributes[:tim]
  image.board = attributes[:board]
  image.set_url
  image
end

Public Instance Methods

download(directory_name) click to toggle source
# File lib/fourchanify/models/image.rb, line 24
def download(directory_name)
  self.directory_name = directory_name
  self.save
  print "."
end
get_url() click to toggle source
# File lib/fourchanify/models/image.rb, line 20
def get_url
  "http://images.4chan.org/#{self.board}/src/#{self.tim}#{self.ext}"
end
save() click to toggle source
# File lib/fourchanify/models/image.rb, line 30
def save
  open("#{self.directory_name}/#{self.tim}#{self.ext}", 'wb') do |file|
    file << open(self.url).read
  end
  sleep 1
end
set_url() click to toggle source
# File lib/fourchanify/models/image.rb, line 16
def set_url
  self.url = self.get_url
end