Class: Fourchanify::Image
- Inherits:
-
Object
- Object
- Fourchanify::Image
- Defined in:
- lib/fourchanify/models/image.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
Returns the value of attribute board.
-
#directory_name ⇒ Object
Returns the value of attribute directory_name.
-
#ext ⇒ Object
Returns the value of attribute ext.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#fsize ⇒ Object
Returns the value of attribute fsize.
-
#tim ⇒ Object
Returns the value of attribute tim.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#board ⇒ Object
Returns the value of attribute board.
3 4 5 |
# File 'lib/fourchanify/models/image.rb', line 3 def board @board end |
#directory_name ⇒ Object
Returns the value of attribute directory_name.
3 4 5 |
# File 'lib/fourchanify/models/image.rb', line 3 def directory_name @directory_name end |
#ext ⇒ Object
Returns the value of attribute ext.
3 4 5 |
# File 'lib/fourchanify/models/image.rb', line 3 def ext @ext end |
#filename ⇒ Object
Returns the value of attribute filename.
3 4 5 |
# File 'lib/fourchanify/models/image.rb', line 3 def filename @filename end |
#fsize ⇒ Object
Returns the value of attribute fsize.
3 4 5 |
# File 'lib/fourchanify/models/image.rb', line 3 def fsize @fsize end |
#tim ⇒ Object
Returns the value of attribute tim.
3 4 5 |
# File 'lib/fourchanify/models/image.rb', line 3 def tim @tim end |
#url ⇒ Object
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_url ⇒ Object
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 |
#save ⇒ Object
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_url ⇒ Object
16 17 18 |
# File 'lib/fourchanify/models/image.rb', line 16 def set_url self.url = self.get_url end |