Module: ScribdFu::InstanceMethods

Defined in:
lib/scribd_fu.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



197
198
199
# File 'lib/scribd_fu.rb', line 197

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

Instance Method Details

#conversion_complete?Boolean

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)


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

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

#conversion_error?Boolean

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

Returns:

  • (Boolean)


231
232
233
# File 'lib/scribd_fu.rb', line 231

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

#conversion_processing?Boolean

Responds true if the conversion is converting

Returns:

  • (Boolean)


214
215
216
# File 'lib/scribd_fu.rb', line 214

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

#conversion_successful?Boolean

Responds true if the document has been converted.

Returns:

  • (Boolean)


226
227
228
# File 'lib/scribd_fu.rb', line 226

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

#destroy_ipaper_documentObject

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



241
242
243
# File 'lib/scribd_fu.rb', line 241

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

#display_ipaper(options = {}) ⇒ Object

Display the iPaper document in a view



246
247
248
249
250
251
252
253
# File 'lib/scribd_fu.rb', line 246

def display_ipaper(options = {})
  id = options.delete(:id) || to_param
  view_mode = options.delete(:view_mode) || 'list'

  <<-END
    <iframe class="scribd_iframe_embed" src="http://www.scribd.com/embeds/#{ipaper_id}/content?start_page=1&view_mode=#{view_mode}&access_key=#{ipaper_access_key}" data-auto-height="true" scrolling="no" id="scribd_#{id}" width="100%" frameborder="0"></iframe><script type="text/javascript">(function() { var scribd = document.createElement("script"); scribd.type = "text/javascript"; scribd.async = true; scribd.src = "http://www.scribd.com/javascripts/embed_code/inject.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(scribd, s); })();</script>
  END
end

#ipaper_documentObject

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



236
237
238
# File 'lib/scribd_fu.rb', line 236

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

#scribdable?Boolean

Checks whether the associated file is convertable to iPaper

Returns:

  • (Boolean)


209
210
211
# File 'lib/scribd_fu.rb', line 209

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

#upload_to_scribdObject

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.



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

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