Class: RemoveBg::Result
- Inherits:
-
Object
- Object
- RemoveBg::Result
- Extended by:
- Forwardable
- Defined in:
- lib/remove_bg/result.rb
Overview
Provides convenience methods to save the processed image, read the image data, and access metadata such as the image height/width and credits charged.
Direct Known Subclasses
Instance Attribute Summary collapse
- #metadata ⇒ RemoveBg::ResultMetadata readonly
- #rate_limit ⇒ RemoveBg::RateLimitInfo readonly
Instance Method Summary collapse
-
#data ⇒ String
Returns the binary data of the processed image.
-
#initialize(download:, metadata:, rate_limit:) ⇒ Result
constructor
A new instance of Result.
-
#save(file_path, overwrite: false) ⇒ nil
Saves the processed image to the path specified.
-
#save!(file_path) ⇒ nil
Saves the processed image to the path specified, overwriting any existing file at the specified path.
Constructor Details
#initialize(download:, metadata:, rate_limit:) ⇒ Result
Returns a new instance of Result.
24 25 26 27 28 |
# File 'lib/remove_bg/result.rb', line 24 def initialize(download:, metadata:, rate_limit:) @download = download @metadata = @rate_limit = rate_limit end |
Instance Attribute Details
#metadata ⇒ RemoveBg::ResultMetadata (readonly)
17 18 19 |
# File 'lib/remove_bg/result.rb', line 17 def @metadata end |
#rate_limit ⇒ RemoveBg::RateLimitInfo (readonly)
20 21 22 |
# File 'lib/remove_bg/result.rb', line 20 def rate_limit @rate_limit end |
Instance Method Details
#data ⇒ String
Returns the binary data of the processed image
54 55 56 57 |
# File 'lib/remove_bg/result.rb', line 54 def data image_file.rewind image_file.read end |
#save(file_path, overwrite: false) ⇒ nil
Saves the processed image to the path specified
35 36 37 38 39 40 41 |
# File 'lib/remove_bg/result.rb', line 35 def save(file_path, overwrite: false) raise FileOverwriteError.new(file_path) if File.exist?(file_path) && !overwrite warn("DEPRECATION WARNING: overwrite: true is deprecated and will be removed from remove_bg 2.0 (use save! instead)") if overwrite FileUtils.cp(image_file, file_path) end |
#save!(file_path) ⇒ nil
Saves the processed image to the path specified, overwriting any existing file at the specified path
47 48 49 |
# File 'lib/remove_bg/result.rb', line 47 def save!(file_path) FileUtils.cp(image_file, file_path) end |