Class: FileConvert::Conversion

Inherits:
Object
  • Object
show all
Defined in:
lib/file_convert/conversion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, remote_file, mime_type) ⇒ FileConvert::File

Downloads remote file from Google Drive with given mime_type

Parameters:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/file_convert/conversion.rb', line 15

def initialize(client, remote_file, mime_type)
  @client = client
  @remote_file = remote_file
  @original_upload_result = remote_file.original_file
  @remote_file_data = remote_file.data
  @mime_type = mime_type

  # Fail if upload errored
  fail data_error_exception if @original_upload_result.error?
  # Fail if requested mime-type is not available
  fail missing_mime_type_exception unless export_links.key?(mime_type)

  @file = fetch_file
  @body = @file.body
  @remote_file.add_conversion(mime_type, self)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/file_convert/conversion.rb', line 4

def body
  @body
end

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/file_convert/conversion.rb', line 3

def file
  @file
end

Instance Method Details

#save(target_path) ⇒ FileConvert::Conversion

Saves result as file

Parameters:

  • target_path (String)

Returns:



37
38
39
# File 'lib/file_convert/conversion.rb', line 37

def save(target_path)
  ::File.open(target_path, 'w') { |file| file.write(@file.body) }
end