Class: Format

Inherits:
Object
  • Object
show all
Defined in:
lib/aniview/util/format.rb

Class Method Summary collapse

Class Method Details

.format_duration(v) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/aniview/util/format.rb', line 2

def self.format_duration v
	hours = Integer((v-(v%3600))/3600)
	minutes = Integer( ((v-(v%60))/60) - (hours * 60))
	seconds = Integer(v%60)
	if hours < 1 and minutes < 1
		return String(seconds)
	else
		seconds = "0" + String(seconds) if seconds < 10
		if hours < 1 
			return "#{String(minutes)}:#{String(seconds)}"
		else
			minutes = "0" + String(minutes) if minutes < 10
			return "#{String(hours)}:#{String(minutes)}:#{String(seconds)}"
		end
	end
end

.format_size(s) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aniview/util/format.rb', line 19

def self.format_size s
	fs = Float(s)

	bytecount = {
		"TB" => 1000000000000.0,
		"GB" => 1000000000.0,
		"MB" => 1000000.0,
		"KB" => 1000.0,
		"B"  => 1.0,
	}
	r = "TB"
	r = "GB" if s < bytecount["TB"]
	r = "MB" if s < bytecount["GB"]
	r = "KB" if s < bytecount["KB"]

	return String( Float(fs/bytecount[r] * 10.0 ).round / 10.0 ) + r
end