Class: Rubyhexagon::Preview Private

Inherits:
Image
  • Object
show all
Defined in:
lib/rubyhexagon/image.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class for post file data. This is mostly an abstraction to have data structures in a more Ruby like nature. This class just holds an adapted version of #save!, to handle the case of preview images having a different MD5 hash sum attribute than they actually should have. That is an e621 issue though.

Author:

  • Maxine Michalski

Since:

  • 1.0.0

Instance Attribute Summary

Attributes inherited from Image

#ext, #height, #md5, #size, #url, #width

Instance Method Summary collapse

Methods inherited from Image

#==, #initialize

Constructor Details

This class inherits a constructor from Rubyhexagon::Image

Instance Method Details

#save!(dirname = './') ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Retrieve data from e621 and save it to file.

Parameters:

  • dirname (String) (defaults to: './')

    path where to save. This needs be an existing directory. This overwrites existing files.

Raises:

  • (ArgumentError)

    Argument given is not an existing directory

Author:

  • Maxine Michalski

Since:

  • 1.0.0



115
116
117
118
119
120
# File 'lib/rubyhexagon/image.rb', line 115

def save!(dirname = './')
  raise ArgumentError, 'Not a directory!' unless File.directory?(dirname)
  File.open("#{dirname}/#{File.basename(@url.path)}", 'w') do |f|
    f.print @url.open(@user_agent).read
  end
end