Module: ScribdFu::InstanceMethods

Defined in:
lib/scribd_fu.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(base)



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

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.



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

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.



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

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

- (Boolean) conversion_processing?

Responds true if the conversion is converting



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

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

- (Boolean) conversion_successful?

Responds true if the document has been converted.



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

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



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

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

- (Object) display_ipaper(options = {})

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

- (Object) ipaper_document

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

- (Boolean) scribdable?

Checks whether the associated file is convertable to iPaper



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

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.



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

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