Class: Fourchanify::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/fourchanify/models/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#boardObject

Returns the value of attribute board.



3
4
5
# File 'lib/fourchanify/models/image.rb', line 3

def board
  @board
end

#directory_nameObject

Returns the value of attribute directory_name.



3
4
5
# File 'lib/fourchanify/models/image.rb', line 3

def directory_name
  @directory_name
end

#extObject

Returns the value of attribute ext.



3
4
5
# File 'lib/fourchanify/models/image.rb', line 3

def ext
  @ext
end

#filenameObject

Returns the value of attribute filename.



3
4
5
# File 'lib/fourchanify/models/image.rb', line 3

def filename
  @filename
end

#fsizeObject

Returns the value of attribute fsize.



3
4
5
# File 'lib/fourchanify/models/image.rb', line 3

def fsize
  @fsize
end

#timObject

Returns the value of attribute tim.



3
4
5
# File 'lib/fourchanify/models/image.rb', line 3

def tim
  @tim
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/fourchanify/models/image.rb', line 3

def url
  @url
end

Class Method Details

.prepare(attributes) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# 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

Instance Method Details

#download(directory_name) ⇒ Object



24
25
26
27
28
# File 'lib/fourchanify/models/image.rb', line 24

def download(directory_name)
  self.directory_name = directory_name
  self.save
  print "."
end

#get_urlObject



20
21
22
# File 'lib/fourchanify/models/image.rb', line 20

def get_url
  "http://images.4chan.org/#{self.board}/src/#{self.tim}#{self.ext}"
end

#saveObject



30
31
32
33
34
35
# 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_urlObject



16
17
18
# File 'lib/fourchanify/models/image.rb', line 16

def set_url
  self.url = self.get_url
end