Module: ScribdFu::InstanceMethods

Defined in:
lib/scribd_fu.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



183
184
185
# File 'lib/scribd_fu.rb', line 183

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)


207
208
209
# File 'lib/scribd_fu.rb', line 207

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)


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

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

#conversion_processing?Boolean

Responds true if the conversion is converting

Returns:

  • (Boolean)


200
201
202
# File 'lib/scribd_fu.rb', line 200

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

#conversion_successful?Boolean

Responds true if the document has been converted.

Returns:

  • (Boolean)


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

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



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

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

#display_ipaper(options = {}) ⇒ Object

Display the iPaper document in a view



232
233
234
235
236
237
238
239
240
241
242
# File 'lib/scribd_fu.rb', line 232

def display_ipaper(options = {})
  <<-END
    <script type="text/javascript" src="http://www.scribd.com/javascripts/view.js"></script>
    <div id="embedded_flash">#{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");
    </script>
  END
end

#ipaper_documentObject

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



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

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

#scribdable?Boolean

Checks whether the associated file is convertable to iPaper

Returns:

  • (Boolean)


195
196
197
# File 'lib/scribd_fu.rb', line 195

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.



190
191
192
# File 'lib/scribd_fu.rb', line 190

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