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.



131
132
133
134
135
136
# File 'lib/api2convert/result.rb', line 131

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:



129
130
131
# File 'lib/api2convert/result.rb', line 129

def job
  @job
end

Instance Method Details

#contents(download_password = nil) ⇒ Object

Download the selected output and return its contents.



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

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).



170
171
172
# File 'lib/api2convert/result.rb', line 170

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.



175
176
177
178
# File 'lib/api2convert/result.rb', line 175

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).



139
140
141
142
143
144
145
146
147
# File 'lib/api2convert/result.rb', line 139

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.



150
151
152
# File 'lib/api2convert/result.rb', line 150

def outputs
  @job.output
end

#save(path_or_dir, download_password = nil) ⇒ Object

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



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

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

#to_sObject



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

def to_s
  inspect
end

#urlObject

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



155
156
157
# File 'lib/api2convert/result.rb', line 155

def url
  output.uri
end