Add file?, text? and image? helpers

This commit is contained in:
Joshua Peek
2011-05-11 17:08:46 -05:00
parent 7f8d0f611e
commit b424c32bb4
2 changed files with 41 additions and 0 deletions

View File

@@ -33,6 +33,23 @@ module Linguist
@mime_type ||= Mime.lookup(extname)
end
def media_type
mime_type.split('/').first
end
def file?
image? || !text? || mime_type == 'octet-stream'
end
def text?
media_type == 'text' ||
mime_type == 'application/json'
end
def image?
['.png', '.jpg', '.jpeg', '.gif'].include?(extname)
end
def to_s
@path.dup
end