Class: Picasa::File

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ 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

#pathObject (readonly)

Returns the value of attribute path


13
14
15
# File 'lib/picasa/file.rb', line 13

def path
  @path
end

Instance Method Details

#binaryObject


27
28
29
# File 'lib/picasa/file.rb', line 27

def binary
  @binary ||= ::File.open(path, "rb").read
end

#content_typeObject

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

#extensionObject


23
24
25
# File 'lib/picasa/file.rb', line 23

def extension
  @extension ||= ::File.extname(path)[1..-1]
end

#nameObject


19
20
21
# File 'lib/picasa/file.rb', line 19

def name
  @name ||= ::File.basename(path, ".*")
end