Module: HelpersView::RenderFileSize

Included in:
RailsHtml
Defined in:
lib/helpers_view/render_file_size.rb

Overview

module RenderFileSize

Instance Method Summary collapse

Instance Method Details

#render_file_size_html(file_size, number_round = 2) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/helpers_view/render_file_size.rb', line 6

def render_file_size_html(file_size, number_round = 2)
  return "#{file_size} B" if file_size < 1024
  return "#{(file_size / 1024.0).round(number_round)} KB" if file_size < 1024 * 1024
  return "#{(file_size / (1024.0 * 1024)).round(number_round)} MB" if file_size < 1024 * 1024 * 1024
  return "#{(file_size / (1024.0 * 1024 * 1024)).round(number_round)} GB" if file_size < 1024 * 1024 * 1024 * 1024

  "#{(file_size / (1024.0 * 1024 * 1024 * 1024)).round(number_round)} TB"
end