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
22
# 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
  @throttle           = Components::Throttle.new(options)

  start :at => options[:starting_at]
end

Instance Method Details

#clearObject

Output



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

def clear
  output.print clear_string
end

#decrementObject

Updating The Bar’s Progress



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

def decrement
  with_update { with_progressables(:decrement) }
end

#finishObject

Stopping The Bar



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

def finish
  with_update { with_progressables(:finish) }
end

#finished?Boolean

Returns:

  • (Boolean)


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

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

#incrementObject



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

def increment
  with_update { with_progressables(:increment) }
end

#inspectObject



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

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

#pauseObject



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

def pause
  with_update { with_timers(:pause) }
end

#progress=(new_progress) ⇒ Object



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

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

#progress_mark=(mark) ⇒ Object

UI Updates



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

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

#refreshObject



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

def refresh
  update
end

#resetObject



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

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

#resumeObject



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

def resume
  with_update { with_timers(:resume) }
end

#start(options = {}) ⇒ Object

Starting The Bar



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

def start(options = {})
  clear

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

#stopObject



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

def stop
  with_update { with_timers(:stop) }
end

#stopped?Boolean Also known as: paused?

Returns:

  • (Boolean)


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

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

#title=(title) ⇒ Object



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

def title=(title)
  with_update { super }
end

#to_s(format_string = nil) ⇒ Object



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

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

  format(format_string)
end