Class: Api2Convert::Result::ConversionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/api2convert/result.rb

Overview

The result of a completed conversion.

The common case is one output: result.save("out.pdf"). Jobs that produce several files expose them via #outputs and #download.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, transport, index = 0, download_password = nil) ⇒ ConversionResult

Returns a new instance of ConversionResult.



162
163
164
165
166
167
# File 'lib/api2convert/result.rb', line 162

def initialize(job, transport, index = 0, download_password = nil)
  @job = job
  @transport = transport
  @index = index
  @download_password = download_password
end

Instance Attribute Details

#jobModel::Job (readonly)

Returns the completed job.

Returns:



160
161
162
# File 'lib/api2convert/result.rb', line 160

def job
  @job
end

Instance Method Details

#contents(download_password = nil) ⇒ Object

Download the selected output and return its contents.



196
197
198
# File 'lib/api2convert/result.rb', line 196

def contents(download_password = nil)
  download.contents(download_password)
end

#download(output_file = nil) ⇒ Object

A FileDownload for a specific output (defaults to the selected one).



201
202
203
# File 'lib/api2convert/result.rb', line 201

def download(output_file = nil)
  FileDownload.new(@transport, output_file.nil? ? output : output_file, @download_password)
end

#inspectObject

Redacted representation — the remembered download password is masked.



206
207
208
209
# File 'lib/api2convert/result.rb', line 206

def inspect
  "#<#{self.class.name} job=#{@job.id.inspect} outputs=#{@job.output.length} " \
    "download_password=#{Support::Secret.mask(@download_password)}>"
end

#outputObject

The selected output file (the first one by default).



170
171
172
173
174
175
176
177
178
# File 'lib/api2convert/result.rb', line 170

def output
  # Any index not present — including a negative one — raises rather than
  # wrapping around.
  if @index.negative? || @index >= @job.output.length
    raise Api2Convert::Error, "The job produced no output files."
  end

  @job.output[@index]
end

#outputsObject

All output files produced by the job.



181
182
183
# File 'lib/api2convert/result.rb', line 181

def outputs
  @job.output
end

#save(path_or_dir, download_password = nil) ⇒ Object

Download the selected output to disk. Returns the path written to.



191
192
193
# File 'lib/api2convert/result.rb', line 191

def save(path_or_dir, download_password = nil)
  download.save(path_or_dir, download_password)
end

#to_sObject



211
212
213
# File 'lib/api2convert/result.rb', line 211

def to_s
  inspect
end

#urlObject

The download URL of the selected output (self-contained, no auth).



186
187
188
# File 'lib/api2convert/result.rb', line 186

def url
  output.uri
end