Class: Picasa::File
- Inherits:
-
Object
- Object
- Picasa::File
- Defined in:
- lib/picasa/file.rb
Defined Under Namespace
Classes: Null
Constant Summary collapse
- KnownExtensions =
%w{jpg jpeg png gif bmp 3gp mp4 mpeg mov wmv asf avi}
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #binary ⇒ Object
-
#content_type ⇒ Object
Returns content type based on file extension You should use something like: ‘file -b –mime-type path/to/file.avi` to be sure what is the proper content type.
- #extension ⇒ Object
-
#initialize(path) ⇒ File
constructor
A new instance of File.
- #name ⇒ Object
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
15 16 17 |
# File 'lib/picasa/file.rb', line 15 def initialize(path) @path = path || raise(ArgumentError.new("path not specified")) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/picasa/file.rb', line 13 def path @path end |
Instance Method Details
#binary ⇒ Object
27 28 29 |
# File 'lib/picasa/file.rb', line 27 def binary @binary ||= ::File.open(path, "rb").read end |
#content_type ⇒ Object
Returns content type based on file extension You should use something like: ‘file -b –mime-type path/to/file.avi` to be sure what is the proper content type
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/picasa/file.rb', line 34 def content_type @content_type ||= case extension when /^jpe?g$/i "image/jpeg" when /^gif$/i "image/gif" when /^png$/i "image/png" when /^bmp$/i "image/bmp" # Videos when /^3gp$/i "video/3gpp" when /^mp4$/i "video/mp4" when /^mpeg$/i "video/mpeg" when /^mov$/i "video/quicktime" when /^wmv$/i "video/x-ms-wmv" when /^asf$/i "video/x-ms-asf" when /^avi$/i "video/avi" else raise UnknownContentType.new("Content type cannot be guessed from file extension: #{extension}") end end |
#extension ⇒ Object
23 24 25 |
# File 'lib/picasa/file.rb', line 23 def extension @extension ||= ::File.extname(path)[1..-1] end |
#name ⇒ Object
19 20 21 |
# File 'lib/picasa/file.rb', line 19 def name @name ||= ::File.basename(path, ".*") end |