class Popro::Progress

Attributes

context[R]

Public Class Methods

new(**options) { |self| ... } click to toggle source
# File lib/popro/progress.rb, line 17
def initialize(**options)
  @started = false

  options = DEFAULT_OPTIONS
            .merge(step: block_given? ? 0 : 1)
            .merge(options)

  @info = Info.new(total: options.delete(:total), current: options.delete(:current))

  options.merge!(progress: self, info: @info)
  @context = Context.new(**options)

  register_aliases
  return unless block_given?

  yield self
  done
end

Public Instance Methods

add(amount) click to toggle source

increase the total

# File lib/popro/progress.rb, line 37
def add(amount)
  @info.total += amount
  self
end

Private Instance Methods

register_aliases() click to toggle source
# File lib/popro/progress.rb, line 44
def register_aliases
  class << self
    %i[each each_will each_gonna to_proc gonna will did formatter start done].each do |method_name|
      define_method method_name do |*args, &block|
        @context.public_send(method_name, *args, &block)
      end
    end

    %i[current total].each do |method_name|
      define_method method_name do
        @info.public_send(method_name)
      end
    end
  end
end