Class: Divshare::DivshareFile
- Inherits:
-
Object
- Object
- Divshare::DivshareFile
- Defined in:
- lib/divshare/divshare_file.rb
Overview
This class represents a file stored at Divshare. Queries from a Divshare::Client to the API return arrays of DivshareFile objects. You can gather any information provided by the API from this object, as well as generate a tag for embedding the file in HTML.
The proper embed tag depends on the file type. The Divshare API doesn’t distinguish these different filetypes, however, so this library tries to figure out the filetype from the file’s extension.
Constant Summary collapse
- ATTRIBUTES =
%w(file_id file_name file_description file_size downloads last_downloaded_at uploaded_at folder_title folder_id)
- AUDIO =
/^\.(mp3)$/i
- VIDEO =
/^\.(avi|wmv|mov|mpg|asf)$/i
- DOCUMENT =
/^\.(doc|pdf|ppt)$/i
- IMAGE =
/^\.(jpg|gif|png)$/i
Instance Attribute Summary collapse
-
#medium ⇒ Object
readonly
Returns the value of attribute medium.
Instance Method Summary collapse
- #audio? ⇒ Boolean
- #document? ⇒ Boolean
-
#embed_tag(opts = {}) ⇒ Object
Image options.
- #image? ⇒ Boolean
-
#initialize(xml = Hpricot("")) ⇒ DivshareFile
constructor
A new instance of DivshareFile.
- #to_s ⇒ Object
- #video? ⇒ Boolean
Constructor Details
#initialize(xml = Hpricot("")) ⇒ DivshareFile
Returns a new instance of DivshareFile.
22 23 24 25 26 27 28 29 30 |
# File 'lib/divshare/divshare_file.rb', line 22 def initialize(xml=Hpricot("")) ATTRIBUTES.each do |attr| if xml.at(attr) value = xml.at(attr).inner_html instance_variable_set("@#{attr}", value) end end @medium = find_medium end |
Instance Attribute Details
#medium ⇒ Object (readonly)
Returns the value of attribute medium.
20 21 22 |
# File 'lib/divshare/divshare_file.rb', line 20 def medium @medium end |
Instance Method Details
#audio? ⇒ Boolean
32 33 34 |
# File 'lib/divshare/divshare_file.rb', line 32 def audio? @medium == "audio" end |
#document? ⇒ Boolean
36 37 38 |
# File 'lib/divshare/divshare_file.rb', line 36 def document? @medium == "document" end |
#embed_tag(opts = {}) ⇒ Object
Image options
:size => :fullsize | :midsize | :thumb
51 52 53 54 |
# File 'lib/divshare/divshare_file.rb', line 51 def (opts={}) return nil if @medium.nil? self.send("#{@medium}_embed_tag_template", opts).gsub('[FILE ID]', @file_id) end |
#image? ⇒ Boolean
44 45 46 |
# File 'lib/divshare/divshare_file.rb', line 44 def image? @medium == "image" end |
#to_s ⇒ Object
56 57 58 59 60 |
# File 'lib/divshare/divshare_file.rb', line 56 def to_s s = "#{file_name} <Divshare::DivshareFile>\n" ATTRIBUTES.each { |a| s << sprintf(" %s: %s\n", a, self.send(a)) } s end |
#video? ⇒ Boolean
40 41 42 |
# File 'lib/divshare/divshare_file.rb', line 40 def video? @medium == "video" end |