Module: ScribdFu::InstanceMethods

Defined in:
lib/scribd_fu.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



169
170
171
# File 'lib/scribd_fu.rb', line 169

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)


193
194
195
# File 'lib/scribd_fu.rb', line 193

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)


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

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

#conversion_processing?Boolean

Responds true if the conversion is converting

Returns:

  • (Boolean)


186
187
188
# File 'lib/scribd_fu.rb', line 186

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

#conversion_successful?Boolean

Responds true if the document has been converted.

Returns:

  • (Boolean)


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

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



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

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

#display_ipaper(options = {}) ⇒ Object

Display the iPaper document in a view



218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/scribd_fu.rb', line 218

def display_ipaper(options = {})
  alt = options.has_key?(:alt) ? options[:alt] : ""

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

#ipaper_documentObject

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



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

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

#scribdable?Boolean

Checks whether the associated file is convertable to iPaper

Returns:

  • (Boolean)


181
182
183
# File 'lib/scribd_fu.rb', line 181

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.



176
177
178
# File 'lib/scribd_fu.rb', line 176

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