class BarOfProgress
Constants
- DEFAULTS
- VERSION
Public Class Methods
new(options = {})
click to toggle source
# File lib/bar-of-progress.rb, line 18 def initialize(options = {}) @options = DEFAULTS.merge(options) #massage data because eww. @options[:total] = to_d(@options[:total]) @options[:length] = @options[:length].to_i end
Public Instance Methods
progress(amount = 0)
click to toggle source
# File lib/bar-of-progress.rb, line 26 def progress(amount = 0) bubbles = clamped_bubbles_for(amount) Output.new(bubbles.floor, partial_bubbles_for(bubbles), @options).to_s end
Private Instance Methods
bubbles_for(amount)
click to toggle source
# File lib/bar-of-progress.rb, line 41 def bubbles_for(amount) (to_d(amount) / @options[:total]) * @options[:length] end
clamp(n, min, max)
click to toggle source
This method is amazing.
# File lib/bar-of-progress.rb, line 46 def clamp(n, min, max) [[n, min].max, max].min end
clamped_bubbles_for(amount)
click to toggle source
# File lib/bar-of-progress.rb, line 33 def clamped_bubbles_for(amount) to_d(clamp(bubbles_for(amount), 0, @options[:length])) end
partial_bubbles_for(bubbles)
click to toggle source
# File lib/bar-of-progress.rb, line 37 def partial_bubbles_for(bubbles) bubbles.truncate(@options[:precision]) % 1 == 0 ? 0 : 1 end
to_d(thing)
click to toggle source
# File lib/bar-of-progress.rb, line 50 def to_d(thing) BigDecimal(thing.to_s) end