Sha256: e034e1c09b9981bf0d5c991671353fafc9030c3f71c1e2d177ae93f1c8258455

Contents?: true

Size: 601 Bytes

Versions: 3

Compression:

Stored size: 601 Bytes

Contents

module WGif
  class InfoDisplayer

    GIGA_SIZE = 1_073_741_824.0
    MEGA_SIZE = 1_048_576.0
    KILO_SIZE = 1024.0

    def display(file_name)
      file_size = readable_file_size(File.size("#{file_name}").to_f)
      puts "#{file_name} is #{file_size}"
    end

    def readable_file_size(size)

      if size < KILO_SIZE
        abb, div = 'Bytes', 1
      elsif size < MEGA_SIZE
        abb, div = 'KB', KILO_SIZE
      elsif size < GIGA_SIZE
        abb, div = 'MB', MEGA_SIZE
      else
        abb, div = 'GB', GIGA_SIZE
      end

      format "%.3f #{abb}",  (size / div)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wgif-0.5.4 lib/wgif/info_displayer.rb
wgif-0.5.3 lib/wgif/info_displayer.rb
wgif-0.5.2 lib/wgif/info_displayer.rb