Class: BarOfProgress
- Inherits:
-
Object
- Object
- BarOfProgress
- Defined in:
- lib/bar-of-progress.rb,
lib/bar_of_progress/version.rb
Constant Summary collapse
- DEFAULTS =
{ :total => 100, :length => 10, :braces => %w{[ ]}, :complete_indicator => "●", :partial_indicator => "◍", :incomplete_indicator => "◌", :precision => 20 }
- VERSION =
"0.1.0"
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BarOfProgress
constructor
A new instance of BarOfProgress.
- #progress(amount = 0) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BarOfProgress
Returns a new instance of BarOfProgress.
17 18 19 20 21 22 23 |
# File 'lib/bar-of-progress.rb', line 17 def initialize( = {}) = DEFAULTS.merge() #massage data because eww. [:total] = [:total].to_d [:length] = [:length].to_i end |
Instance Method Details
#progress(amount = 0) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/bar-of-progress.rb', line 25 def progress(amount = 0) bubbles = clamp(((amount.to_d / [:total]) * [:length]), 0, [:length]).to_d full_bubbles = bubbles.floor partial_bubbles = bubbles.truncate([:precision]) % 1 == 0 ? 0 : 1 "#{@options[:braces][0]}#{chars(@options[:complete_indicator], full_bubbles)}#{chars(@options[:partial_indicator], partial_bubbles)}#{chars(@options[:incomplete_indicator], (@options[:length] - full_bubbles - partial_bubbles))}#{@options[:braces][1]}" end |