Class: Snap::SnapFile
- Inherits:
-
Object
- Object
- Snap::SnapFile
- Defined in:
- lib/snap/snap_file.rb
Instance Method Summary collapse
- #directory? ⇒ Boolean
-
#icon ⇒ Object
TODO: Get this HTML outta here.
- #image? ⇒ Boolean
-
#initialize(file_name) ⇒ SnapFile
constructor
A new instance of SnapFile.
- #mtime ⇒ Object
- #name ⇒ Object
- #path ⇒ Object
- #relative_to(dir) ⇒ Object
- #size ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(file_name) ⇒ SnapFile
Returns a new instance of SnapFile.
3 4 5 |
# File 'lib/snap/snap_file.rb', line 3 def initialize(file_name) @path = file_name.sub("//", "/") end |
Instance Method Details
#directory? ⇒ Boolean
59 60 61 |
# File 'lib/snap/snap_file.rb', line 59 def directory? type.match("directory") end |
#icon ⇒ Object
TODO: Get this HTML outta here
49 50 51 52 53 |
# File 'lib/snap/snap_file.rb', line 49 def icon return "<img src=\"/__snap__/icons/dir.png\"/>" if directory? return "<img src=\"/__snap__/icons/image.png\"/>" if image? return "<img src=\"/__snap__/icons/text.png\"/>" end |
#image? ⇒ Boolean
55 56 57 |
# File 'lib/snap/snap_file.rb', line 55 def image? type.match("image") end |
#mtime ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/snap/snap_file.rb', line 27 def mtime return if File.symlink?(@path) mtime = File.mtime(@path) if (mtime.to_i > Time.now.to_i - 24*60*60) mtime.strftime("%I:%M:%S %p") else mtime.strftime("%d-%m-%Y") end end |
#name ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/snap/snap_file.rb', line 7 def name if @path && @path.match("/") @path.split("/").last else @path end end |
#path ⇒ Object
15 16 17 |
# File 'lib/snap/snap_file.rb', line 15 def path @path end |
#relative_to(dir) ⇒ Object
19 20 21 |
# File 'lib/snap/snap_file.rb', line 19 def relative_to(dir) rel = @path.sub(dir, "") end |
#size ⇒ Object
23 24 25 |
# File 'lib/snap/snap_file.rb', line 23 def size File.size(@path) end |
#type ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/snap/snap_file.rb', line 37 def type type = Rack::Mime::MIME_TYPES[File.extname(path)] if type.nil? escaped_path = @path.gsub(" ", "\\ ") type = `file #{escaped_path}`.strip.sub(/.*:\s*/, "") type = "executable" if type.match("executable") end type end |