Class: Onboardable::List::Base

Inherits:
Object
  • Object
show all
Includes:
Navigation
Defined in:
lib/onboardable/list/base.rb

Overview

The List class manages a sequence of steps in an onboarding process, tracking progress and current state.

Constant Summary collapse

PROGRESS_CALCULATION =
->(step_index, steps_size) { (step_index.to_f / steps_size) * 100 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Navigation

#current_step?, #first_step, #first_step?, #last_step, #last_step?, #next_step, #next_step!, #next_step?, #prev_step, #prev_step!, #prev_step?

Constructor Details

#initialize(steps, current_step, options = {}) ⇒ Base

Initializes a new instance of List with steps and a current step.

Parameters:

  • steps (Array<Step>)

    An array of steps comprising the onboarding process.

  • current_step (Step)

    The step currently active in the process.

  • options (Hash) (defaults to: {})

    An options hash for the list.



22
23
24
25
26
# File 'lib/onboardable/list/base.rb', line 22

def initialize(steps, current_step, options = {})
  self.steps = steps
  self.current_step = current_step
  self.options = options
end

Instance Attribute Details

#current_stepStep

Returns The current step in the list.

Returns:

  • (Step)

    The current step in the list.



15
16
17
# File 'lib/onboardable/list/base.rb', line 15

def current_step
  @current_step
end

#stepsArray<Step>

Returns The steps in the list.

Returns:

  • (Array<Step>)

    The steps in the list.



12
13
14
# File 'lib/onboardable/list/base.rb', line 12

def steps
  @steps
end

Instance Method Details

#progress(progress_calculation = nil) ⇒ Float

Calculates and returns the onboarding progress as a percentage.

Parameters:

  • progress_calculation (Proc, nil) (defaults to: nil)

    An optional custom calculation for progress.

Returns:

  • (Float)

    The percentage of steps completed in the onboarding process.



32
33
34
35
# File 'lib/onboardable/list/base.rb', line 32

def progress(progress_calculation = nil)
  progress_calculation ||= options.fetch(:progress_calculation, PROGRESS_CALCULATION)
  Float(progress_calculation[step_index(current_step), steps.size])
end