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.
Constructor Details
#initialize(download:, metadata:, rate_limit:) ⇒ Result
Returns a new instance of Result.
22 23 24 25 26 |
# File 'lib/remove_bg/result.rb', line 22 def initialize(download:, metadata:, rate_limit:) @download = download @metadata = @rate_limit = rate_limit end |
Instance Attribute Details
#metadata ⇒ RemoveBg::ResultMetadata (readonly)
15 16 17 |
# File 'lib/remove_bg/result.rb', line 15 def @metadata end |
#rate_limit ⇒ RemoveBg::RateLimitInfo (readonly)
18 19 20 |
# File 'lib/remove_bg/result.rb', line 18 def rate_limit @rate_limit end |
Instance Method Details
#data ⇒ String
Returns the binary data of the processed image
44 45 46 47 |
# File 'lib/remove_bg/result.rb', line 44 def data image_file.rewind image_file.read end |
#save(file_path, overwrite: false) ⇒ nil
Saves the processed image to the path specified
33 34 35 36 37 38 39 |
# File 'lib/remove_bg/result.rb', line 33 def save(file_path, overwrite: false) if File.exist?(file_path) && !overwrite raise FileOverwriteError.new(file_path) end FileUtils.cp(image_file, file_path) end |