Class: FileConvert::Conversion
- Inherits:
-
Object
- Object
- FileConvert::Conversion
- Defined in:
- lib/file_convert/conversion.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#initialize(client, remote_file, mime_type) ⇒ FileConvert::File
constructor
Downloads remote file from Google Drive with given mime_type.
-
#save(target_path) ⇒ FileConvert::Conversion
Saves result as file.
Constructor Details
#initialize(client, remote_file, mime_type) ⇒ FileConvert::File
Downloads remote file from Google Drive with given mime_type
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/file_convert/conversion.rb', line 4 def body @body end |
#file ⇒ Object (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
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 |