Class: ProgressBar::Base

Inherits:
Object
  • Object
show all
Includes:
Depreciable, Formatter, LengthCalculator
Defined in:
lib/progress_bar/base.rb

Constant Summary collapse

DEFAULT_OUTPUT_STREAM =
STDOUT

Constants included from Depreciable

Depreciable::DEPRECATION_DATE

Constants included from Formatter

Formatter::DEFAULT_FORMAT_STRING, Formatter::DEFAULT_TITLE

Instance Method Summary collapse

Methods included from Depreciable

#backwards_compatible_args_to_options_conversion, #bar_mark=, #current, #file_transfer_mode, #format=, #format_arguments=, #halt, #inc, #set, #smoothing, #smoothing=, #start_time, #start_time=, #title_width, #title_width=

Methods included from Formatter

#format, #progress, #total

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/progress_bar/base.rb', line 9

def initialize(*args)
  options             = args.empty? ? {} : backwards_compatible_args_to_options_conversion(args)

  self.output         = options[:output]                || DEFAULT_OUTPUT_STREAM

  super(options)

  @bar                = Components::Bar.new(options)
  @estimated_time     = Components::EstimatedTimer.new(options)
  @elapsed_time       = Components::ElapsedTimer.new

  start :at => options[:starting_at]
end

Instance Method Details

#clearObject

Output



100
101
102
# File 'lib/progress_bar/base.rb', line 100

def clear
  output.print clear_string
end

#decrementObject

Updating The Bar’s Progress



38
39
40
# File 'lib/progress_bar/base.rb', line 38

def decrement
  with_update { with_progressables(:decrement) }
end

#finishObject

Stopping The Bar



53
54
55
# File 'lib/progress_bar/base.rb', line 53

def finish
  with_update { with_progressables(:finish) }
end

#finished?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/progress_bar/base.rb', line 82

def finished?
  @bar.progress == @bar.total
end

#incrementObject



42
43
44
# File 'lib/progress_bar/base.rb', line 42

def increment
  with_update { with_progressables(:increment) }
end

#inspectObject



114
115
116
# File 'lib/progress_bar/base.rb', line 114

def inspect
  "#<ProgressBar:#{progress}/#{total}>"
end

#pauseObject



57
58
59
# File 'lib/progress_bar/base.rb', line 57

def pause
  with_update { with_timers(:pause) }
end

#progress=(new_progress) ⇒ Object



46
47
48
# File 'lib/progress_bar/base.rb', line 46

def progress=(new_progress)
  with_update { with_progressables(:progress=, new_progress) }
end

#progress_mark=(mark) ⇒ Object

UI Updates



89
90
91
# File 'lib/progress_bar/base.rb', line 89

def progress_mark=(mark)
  with_update { @bar.progress_mark = mark }
end

#refreshObject



104
105
106
# File 'lib/progress_bar/base.rb', line 104

def refresh
  update
end

#resetObject



69
70
71
72
73
74
# File 'lib/progress_bar/base.rb', line 69

def reset
  with_update do
    @bar.reset
    with_timers(:reset)
  end
end

#resumeObject



65
66
67
# File 'lib/progress_bar/base.rb', line 65

def resume
  with_update { with_timers(:resume) }
end

#start(options = {}) ⇒ Object

Starting The Bar



26
27
28
29
30
31
32
33
# File 'lib/progress_bar/base.rb', line 26

def start(options = {})
  clear

  with_update do
    with_progressables(:start, options)
    @elapsed_time.start
  end
end

#stopObject



61
62
63
# File 'lib/progress_bar/base.rb', line 61

def stop
  with_update { with_timers(:stop) }
end

#stopped?Boolean Also known as: paused?

Returns:

  • (Boolean)


76
77
78
# File 'lib/progress_bar/base.rb', line 76

def stopped?
  @estimated_time.stopped? && @elapsed_time.stopped?
end

#title=(title) ⇒ Object



93
94
95
# File 'lib/progress_bar/base.rb', line 93

def title=(title)
  with_update { super }
end

#to_s(format_string = nil) ⇒ Object



108
109
110
111
112
# File 'lib/progress_bar/base.rb', line 108

def to_s(format_string = nil)
  format_string ||= @format_string

  format(format_string)
end