Module: Vidibus::Fileinfo
- Defined in:
- lib/vidibus/fileinfo.rb,
lib/vidibus/fileinfo/base.rb,
lib/vidibus/fileinfo/version.rb,
lib/vidibus/fileinfo/processor/audio.rb,
lib/vidibus/fileinfo/processor/image.rb,
lib/vidibus/fileinfo/processor/video.rb
Defined Under Namespace
Modules: Processor Classes: Base, DataError, Error, FileAccessError, NoFileError, NoFormatError, PathError, ProcessorError, UnitError, UnsupportedFormatError
Constant Summary collapse
- VERSION =
'1.2.0'
Class Method Summary collapse
-
.bytes(value) ⇒ Object
Converts given size string with unit to bytes number.
-
.format(path) ⇒ Object
Returns the format of a given file path.
-
.formats ⇒ Object
Returns a list of processable formats.
-
.processor(format) ⇒ Object
Returns a processor class for given format.
-
.processors ⇒ Object
Returns a list of available processors.
Class Method Details
.bytes(value) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vidibus/fileinfo.rb', line 52 def bytes(value) if value.is_a?(String) value =~ /([\d\.]+)\s*(\w*)/i size = $1.to_f unit = $2.strip.upcase if $2 power = case unit when "B", "" then 0 when "K", "KB" then 1 when "M", "MB" then 2 when "G", "GB" then 3 when "T", "TB" then 4 else raise UnitError end factor = 1024**power (size*factor).round elsif value.is_a?(Float) value.round elsif value.is_a?(Integer) value else raise ArgumentError end end |
.format(path) ⇒ Object
Returns the format of a given file path. If no format can be detected, a NoFormatError will be raised.
39 40 41 42 43 44 45 |
# File 'lib/vidibus/fileinfo.rb', line 39 def format(path) if path =~ /(?:\.)([a-z0-9]+)$/i $1.downcase else raise NoFormatError end end |
.formats ⇒ Object
Returns a list of processable formats.
27 28 29 |
# File 'lib/vidibus/fileinfo.rb', line 27 def formats @formats ||= mapping.keys.sort end |
.processor(format) ⇒ Object
Returns a processor class for given format. If no processor matches, an UnsupportedFormatError will be raised.
33 34 35 |
# File 'lib/vidibus/fileinfo.rb', line 33 def processor(format) mapping[format.to_s] or raise UnsupportedFormatError end |