class Headway::Progress::Stage

Public Class Methods

new(progress: START_PERCENT) click to toggle source
# File lib/headway/progress.rb, line 48
def initialize(progress: START_PERCENT)
  @progress = progress
  @children = nil
end

Public Instance Methods

cloned() click to toggle source
# File lib/headway/progress.rb, line 74
def cloned
  Stage.new progress: @progress
end
percentage() click to toggle source
# File lib/headway/progress.rb, line 53
def percentage
  if @children
    @children.inject(0.0) { |total, child| total += child.percentage } / (@children.size)
  else
    @progress
  end
end
promote_to_multistage(stages:) click to toggle source
# File lib/headway/progress.rb, line 61
def promote_to_multistage(stages:)
  @children = Array.new(stages - 1) { Stage.new }
  @children.unshift cloned
end
set_percentage(percentage) click to toggle source
# File lib/headway/progress.rb, line 66
def set_percentage(percentage)
  @progress = percentage
end
stages() click to toggle source
# File lib/headway/progress.rb, line 70
def stages
  @children&.map(&:stages) || self
end