Class: Dropsite::SiteFile
- Defined in:
- lib/dropsite/site_file.rb
Constant Summary collapse
- EXTENSIONS =
{ :audio => %w[abs aif aifc aiff au kar m3u mid midi mp1 mp2 mp3 mpa mpega pls smf snd ulw wav], :excel => %w[xls xlsx], :image => %w[art bmp dib gif ief jpe jpeg jpg mac pbm pct pgm pic pict png pnm pnt ppm psd qti qtif ras rgb svg svgz tif tiff wbmp xbm xpm xwd], :pdf => %w[pdf], :ruby => %w[rb rhtml erb], :text => %w[body css etx htc htm html jad java js rtf rtx tsv txt wml wmls], :video => %w[asf asx avi avx dv flv mov movie mp4 mpe mpeg mpg mpv2 qt wmv], :word => %w[doc docx] }
Instance Attribute Summary collapse
-
#abs_path ⇒ Object
Returns the value of attribute abs_path.
-
#size_in_bytes ⇒ Object
Returns the value of attribute size_in_bytes.
Attributes inherited from SiteItem
Attributes included from RenderHelper
Instance Method Summary collapse
- #file_type ⇒ Object
-
#initialize(rel_path, abs_path = nil, site = nil) ⇒ SiteFile
constructor
A new instance of SiteFile.
-
#size ⇒ Object
Human readable file size.
- #to_s ⇒ Object
Methods inherited from SiteItem
#<=>, #error, #name, #notice, #top_level?, #warning
Methods included from RenderHelper
#back_link, #each_parent_directory_link_tag, #get_binding, #image_tag, #javascript_include_tag, #link, #page_asset_image_tag, #page_assets_link_base, #parent_dir_name, #parent_directory_link_tag, #plugin_assets_link_base, #stylesheet_link_tag, #url_for
Constructor Details
#initialize(rel_path, abs_path = nil, site = nil) ⇒ SiteFile
Returns a new instance of SiteFile.
16 17 18 19 20 21 |
# File 'lib/dropsite/site_file.rb', line 16 def initialize(rel_path, abs_path=nil, site=nil) @path = rel_path @abs_path = abs_path @size_in_bytes = File.size(abs_path) if abs_path @site = site end |
Instance Attribute Details
#abs_path ⇒ Object
Returns the value of attribute abs_path.
14 15 16 |
# File 'lib/dropsite/site_file.rb', line 14 def abs_path @abs_path end |
#size_in_bytes ⇒ Object
Returns the value of attribute size_in_bytes.
14 15 16 |
# File 'lib/dropsite/site_file.rb', line 14 def size_in_bytes @size_in_bytes end |
Instance Method Details
#file_type ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/dropsite/site_file.rb', line 23 def file_type if File.extname(name).empty? :unknown else ext = File.extname(name).sub(/^\./, '') EXTENSIONS.each {|k, v| return k if v.include? ext} return :unknown end end |
#size ⇒ Object
Human readable file size
34 35 36 37 38 39 40 41 |
# File 'lib/dropsite/site_file.rb', line 34 def size return '' if !@size_in_bytes return '0 B' if @size_in_bytes == 0 units = %w{B KB MB GB TB} e = (Math.log(@size_in_bytes)/Math.log(1024)).floor s = "%.1f" % (@size_in_bytes.to_f / 1024 ** e) s.sub(/\.?0*$/, " #{units[e]}") end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/dropsite/site_file.rb', line 43 def to_s "SiteFile(#{@path})" end |