Class: RemoveBg::Result

Inherits:
Object
  • Object
show all
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

CompositeResult

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#metadataRemoveBg::ResultMetadata (readonly)



15
16
17
# File 'lib/remove_bg/result.rb', line 15

def 
  @metadata
end

#rate_limitRemoveBg::RateLimitInfo (readonly)



18
19
20
# File 'lib/remove_bg/result.rb', line 18

def rate_limit
  @rate_limit
end

Instance Method Details

#dataString

Returns the binary data of the processed image

Returns:

  • (String)


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

Parameters:

  • file_path (string)
  • overwrite (boolean) (defaults to: false)

    Overwrite any existing file at the specified path

Returns:

  • (nil)


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