Sha256: 462bc274783f5457e6f60c9e8cf2b3959d8b8a80523dfb93a817f1bb5259fe5a
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
require "mireru/widget/image" require "mireru/widget/video" require "mireru/widget/pdf" require "mireru/widget/svg" require "mireru/widget/text" require "mireru/widget/binary" module Mireru module Widget module_function def create(file, width, height) if image?(file) widget = Mireru::Widget::Image.new(file, width, height) elsif video?(file) or music?(file) widget = Mireru::Widget::Video.new(file) elsif pdf?(file) widget = Mireru::Widget::PDF.new(file) elsif svg?(file) widget = Mireru::Widget::SVG.new(file) elsif text?(file) widget = Mireru::Widget::Text.new(file) else widget = Mireru::Widget::Binary.new(file) end widget end def image?(file) /\.(png|jpe?g|gif|ico|ani|bmp|pnm|ras|tga|tiff|xbm|xpm)\z/i =~ file end def music?(file) /\.(og[ag]|wav|acc|mp3|m4a|wma|flac|tta|aiff|ape|tak)\z/i =~ file end def video?(file) /\.(ogm|mp4|m4v|flv|mpe?g2?|ts|mov|avi|divx|mkv|wmv|asf|wmx)\z/i =~ file end def pdf?(file) /\.pdf\z/i =~ file end def svg?(file) /\.svg\z/i =~ file end def text?(file) return false if binary?(file) File.read(file).valid_encoding? end def binary?(file) /\.(la|lo|o|so|a|dll|exe|msi|tar|gz|zip|7z|lzh|rar|iso)\z/i =~ file end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mireru-0.9.0 | lib/mireru/widget.rb |