mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
fix pretty bytes (i hope)
This commit is contained in:
parent
f8f8fe1a22
commit
ae87b48bef
1 changed files with 18 additions and 9 deletions
|
@ -10,15 +10,24 @@ class Numeric
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_bytes_pretty
|
def to_bytes_pretty
|
||||||
space = (self.to_f / ONE_MEGABYTE).round(2)
|
computed = nil
|
||||||
space = space.to_i if space.denominator == 1
|
unit = nil
|
||||||
# if space >= 1000000
|
{
|
||||||
# "#{space/1000000} TB"
|
'B' => 1000,
|
||||||
if space >= 1000
|
'KB' => 1000 * 1000,
|
||||||
"#{(space/1000).to_comma_separated} GB"
|
'MB' => 1000 * 1000 * 1000,
|
||||||
else
|
'GB' => 1000 * 1000 * 1000 * 1000,
|
||||||
"#{space.to_comma_separated} MB"
|
'TB' => 1000 * 1000 * 1000 * 1000 * 1000
|
||||||
end
|
}.each_pair { |e, s|
|
||||||
|
if self < s
|
||||||
|
computed = (self.to_f / (s / 1000)).round(2)
|
||||||
|
unit = e
|
||||||
|
break
|
||||||
|
end
|
||||||
|
}
|
||||||
|
computed = computed.to_i if computed.modulo(1) == 0.0
|
||||||
|
|
||||||
|
"#{computed} #{unit}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_comma_separated
|
def to_comma_separated
|
||||||
|
|
Loading…
Add table
Reference in a new issue