Sha256: 176371a929c334c107edb565b259edcf73d220ccff18106f10724f67f6ddf0ec

Contents?: true

Size: 589 Bytes

Versions: 3

Compression:

Stored size: 589 Bytes

Contents

module WGif
  class InfoDisplayer

    GIGA_SIZE = 1073741824.0
    MEGA_SIZE = 1048576.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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wgif-0.5.1 lib/wgif/info_displayer.rb
wgif-0.5.0 lib/wgif/info_displayer.rb
wgif-0.4.0 lib/wgif/info_displayer.rb