Class: ProgressRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/downloader_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(total) ⇒ ProgressRunner

Returns a new instance of ProgressRunner.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/downloader_file.rb', line 21

def initialize(total)
	@total = total
	@progress = 0
	@progress_bar = ProgressBar.create(
		:total => @total,
		:format => "%a %b\u{15E7}%i %p%% %t",
		:progress_mark => ' ',
		:remainder_mark => "\u{FF65}"
	)
	set_title
end

Instance Method Details

#download(segment) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/downloader_file.rb', line 33

def download(segment)
	begin
		yield
		if @progress < @total
			@progress += segment
			@progress = @total if @progress > @total
			set_title
			@progress_bar.progress = @progress
		elsif @progress == 0
			@progress_bar.finish
		end
	rescue
		@progress_bar.stop
		raise
	end
end

#set_titleObject



50
51
52
# File 'lib/downloader_file.rb', line 50

def set_title
	@progress_bar.title = "#{@progress.to_i.to_filesize}/#{@total.to_i.to_filesize}"
end