Sha256: 8f9b08f10c2d25673cbfb0c76179f77d28731aba68afa5a38d66729ed73a9899

Contents?: true

Size: 1.41 KB

Versions: 13

Compression:

Stored size: 1.41 KB

Contents

module Picasa
  class File
    KnownExtensions = %w{jpg jpeg png gif bmp 3gp mp4 mpeg mov wmv asf avi}

    class Null
      def path; end
      def name; end
      def extension; end
      def binary; end
      def content_type; end
    end

    attr_reader :path

    def initialize(path)
      @path = path || raise(ArgumentError.new("path not specified"))
    end

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

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

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

    # 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
    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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
picasa-0.9.1 lib/picasa/file.rb
picasa-0.9.0 lib/picasa/file.rb
picasa-0.8.0 lib/picasa/file.rb
picasa-0.7.5 lib/picasa/file.rb
picasa-0.7.4 lib/picasa/file.rb
picasa-0.7.3 lib/picasa/file.rb
picasa-0.7.2 lib/picasa/file.rb
picasa-0.7.1 lib/picasa/file.rb
picasa-0.7.0 lib/picasa/file.rb
picasa-0.6.7 lib/picasa/file.rb
picasa-0.6.6 lib/picasa/file.rb
picasa-0.6.5 lib/picasa/file.rb
picasa-0.6.4 lib/picasa/file.rb