Class: Refinery::Products::Digidownload

Inherits:
Core::BaseModel
  • Object
show all
Defined in:
app/models/refinery/products/digidownload.rb

Constant Summary collapse

@@icon_hash =

#########################################################################

nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.category_to_icon(category) ⇒ Object


category_to_icon – returns an icon image name for a given category args:

category -- symbol for category



87
88
89
# File 'app/models/refinery/products/digidownload.rb', line 87

def self.category_to_icon(category)
  return icon_hash[category] || icon_hash[:unknown]
end

.icon_hashObject


icon_hash – returns the icon hash; inits if first time




65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/refinery/products/digidownload.rb', line 65

def self.icon_hash()
  @@icon_hash ||= {
    :powerpoint    => "PowerPoint.png",
    :excel      => "Excel.png",
    :word       => "Word.png",
    :pdf        => "pdf-icon.png",
    :zip        => "zip_thumb.png",
    :text       => "muku-doc-font-128.png",
    :audio      => "audio-icon.png",
    :video      => "video-icon.png",
    :image      => "camera-icon.png",
    :html       => "html-icon.png",
      
    :unknown    => "warning-icon.png"
  }
end

.icon_hash=(icon_hash) ⇒ Object



need accessor functions which look at restrict_count and/or restrict_date
to determine if it's okay to download
also to verify the token

icon_hash= – resets the icon hash to another set of image files




58
59
60
# File 'app/models/refinery/products/digidownload.rb', line 58

def self.icon_hash=(icon_hash)
  @@icon_hash = icon_hash
end

.to_category(content_type) ⇒ Object


to_category – returns a category type (symbol) for the content-type args:

content_type -- string in standard MIME type



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/models/refinery/products/digidownload.rb', line 96

def self.to_category(content_type)
  
  return :unknown if content_type.blank?
  
  tokens = content_type.split("/")
  category = tokens[0].to_sym
  if category == :application
    case tokens[1]
      when /ms-excel|spreadsheet/            then category = :excel
      when /ms-?word|wordprocessing/         then category = :word
      when /ms-powerpoint|presentation/      then category = :powerpoint
      when /wordperfect/    then category = :word
      when /pdf/            then category = :pdf
      when /zip/            then category = :zip
    else
      category = :unknown
    end  # case
  elsif category == :text
    case tokens[1]
      when /html/       then category = :html
    end  # case
  end   # application or text handling
    
  return category
end

Instance Method Details

#clean_restrictionsObject




156
157
158
159
# File 'app/models/refinery/products/digidownload.rb', line 156

def clean_restrictions
  self.restrict_count = nil unless self.restrict_count.nil? || self.restrict_count > 0
  self.restrict_days  = nil unless self.restrict_days.nil?  || self.restrict_days > 0
end

#digi_select_listObject





124
125
126
127
# File 'app/models/refinery/products/digidownload.rb', line 124

def digi_select_list
  return ::Refinery::Products::Product.digi_select_list if self.product.nil?
  return [ ["no product selected",nil], [self.product.name, self.product_id] ]
end

#generate_download_tokenObject





149
150
151
# File 'app/models/refinery/products/digidownload.rb', line 149

def generate_download_token
  self.download_token = ::Refinery::AuthKey.make_token
end

#to_categoryObject





131
132
133
# File 'app/models/refinery/products/digidownload.rb', line 131

def to_category()
  Digidownload.to_category(self.doc_content_type)
end

#to_playerObject




138
139
140
141
142
143
144
145
# File 'app/models/refinery/products/digidownload.rb', line 138

def to_player()
 case to_category
   when :audio then "<audio src='#{self.doc.url}' controls preload='auto' autobuffer></audio>"
   when :video then "<video src='#{self.doc.url}' controls autobuffer></video>"
 else
   ""    # returns nothing
 end  # case
end