lib/vidibus/fileinfo.rb
# Converts given size string with unit to bytes number.
#
# Example:
#   Vidibus::Fileinfo.bytes("0.23 MB") #=> 241172
#
Converts given size string with unit to bytes number.
Converts given size string with unit to bytes number .
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
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
Converts given size string with unit to bytes number.
Converts given size string with unit to bytes number .
value
<not_specific>