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.



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

#metadataRemoveBg::ResultMetadata (readonly)



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

def 
  @metadata
end

#rate_limitRemoveBg::RateLimitInfo (readonly)



20
21
22
# File 'lib/remove_bg/result.rb', line 20

def rate_limit
  @rate_limit
end

Instance Method Details

#dataString

Returns the binary data of the processed image

Returns:

  • (String)


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

Parameters:

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

    Overwrite any existing file at the specified path

Returns:

  • (nil)

Raises:



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

Parameters:

  • file_path (string)

Returns:

  • (nil)


47
48
49
# File 'lib/remove_bg/result.rb', line 47

def save!(file_path)
  FileUtils.cp(image_file, file_path)
end