Module: ScribdFu::InstanceMethods

Defined in:
lib/scribd_fu.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(base)



204
205
206
# File 'lib/scribd_fu.rb', line 204

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

- (Boolean) conversion_complete?

Responds true if the conversion is complete -- note that this gives no indication as to whether the conversion had an error or was succesful, just that the conversion completed.

Returns:

  • (Boolean)


228
229
230
# File 'lib/scribd_fu.rb', line 228

def conversion_complete?
  ipaper_document && ipaper_document.conversion_status != 'PROCESSING'
end

- (Boolean) conversion_error?

Responds true if there was a conversion error while converting to iPaper.

Returns:

  • (Boolean)


238
239
240
# File 'lib/scribd_fu.rb', line 238

def conversion_error?
  ipaper_document && ipaper_document.conversion_status == 'ERROR'
end

- (Boolean) conversion_processing?

Responds true if the conversion is converting

Returns:

  • (Boolean)


221
222
223
# File 'lib/scribd_fu.rb', line 221

def conversion_processing?
  !(conversion_complete? || conversion_successful? || conversion_error?)
end

- (Boolean) conversion_successful?

Responds true if the document has been converted.

Returns:

  • (Boolean)


233
234
235
# File 'lib/scribd_fu.rb', line 233

def conversion_successful?
  ipaper_document && ipaper_document.conversion_status =~ /^DISPLAYABLE|DONE$/
end

- (Object) destroy_ipaper_document

Destroys the scribd document for this record. This is called before_destroy



248
249
250
# File 'lib/scribd_fu.rb', line 248

def destroy_ipaper_document
  ScribdFu::destroy(ipaper_document) if ipaper_document
end

- (Object) display_ipaper(options = {})

Display the iPaper document in a view



253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/scribd_fu.rb', line 253

def display_ipaper(options = {})
  id = options.delete(:id)
  <<-END
    <script type="text/javascript" src="http://www.scribd.com/javascripts/view.js"></script>
    <div id="embedded_flash#{id}">#{options.delete(:alt)}</div>
    <script type="text/javascript">
      var scribd_doc = scribd.Document.getDoc(#{ipaper_id}, '#{ipaper_access_key}');
      #{js_params(options)}
      scribd_doc.write("embedded_flash#{id}");
    </script>
  END
end

- (Object) ipaper_document

Responds the Scribd::Document associated with this model, or nil if it does not exist.



243
244
245
# File 'lib/scribd_fu.rb', line 243

def ipaper_document
  @document ||= ScribdFu::load_ipaper_document(ipaper_id)
end

- (Boolean) scribdable?

Checks whether the associated file is convertable to iPaper

Returns:

  • (Boolean)


216
217
218
# File 'lib/scribd_fu.rb', line 216

def scribdable?
  ContentTypes.include?(get_content_type) && ipaper_id.blank?
end

- (Object) upload_to_scribd

Upload the associated file to Scribd for iPaper conversion This is called after_save and cannot be called earlier, so don't get any ideas.



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

def upload_to_scribd
  ScribdFu::upload(self, file_path) if scribdable?
end