Class: PopCap::Formatters::Filesize

Inherits:
Formatter
  • Object
show all
Defined in:
lib/pop_cap/formatters/filesize.rb

Overview

Public: This class formats a filesize as human readable, following a UNIX formatting standard.

filesize - Provide a filesize as string, integer, or float.

Instance Attribute Summary

Attributes inherited from Formatter

#options, #value

Instance Method Summary collapse

Methods inherited from Formatter

format, #initialize, subclasses, subclasses_demodulized

Constructor Details

This class inherits a constructor from PopCap::Formatters::Formatter

Instance Method Details

#formatObject

Public: This method will format the filesize. It raises a warning message if size is greater than 999 terabytes.

Examples

fs = Filesize.new(12345678)
fs.format
# => '11.8M'


22
23
24
25
26
# File 'lib/pop_cap/formatters/filesize.rb', line 22

def format
  return if value.to_i == 0
  return warning_message if too_large?
  converted_filesize.to_s + measurement_character
end