class SakaiInfo::Util

Constants

FILESIZE_LABELS

misc support functions

Public Class Methods

format_entity_date(raw) click to toggle source
# File lib/sakai-info/util.rb, line 40
def self.format_entity_date(raw)
  if raw =~ /^(....)(..)(..)(..)(..)(..).*$/
    # I believe these are usually in UTC
    Time.utc($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i).getlocal
  else
    raw
  end
end
format_filesize(i_size) click to toggle source
# File lib/sakai-info/util.rb, line 16
def self.format_filesize(i_size)
  size = i_size.to_f
  negative = false

  if size < 0
    negative = true
    size = -size
  end

  label = 0
  (FILESIZE_LABELS.size - 1).times do
    if size >= 1024.0
      size = size / 1024.0
      label += 1
    end
  end

  if size >= 100.0 or label == 0
    "#{negative ? "-" : ""}#{size.to_i.to_s} #{FILESIZE_LABELS[label]}"
  else
    "#{negative ? "-" : ""}#{sprintf("%.1f", size)} #{FILESIZE_LABELS[label]}"
  end
end