Class: Onboardable::List::Base
- Inherits:
-
Object
- Object
- Onboardable::List::Base
- Includes:
- Navigation
- Defined in:
- lib/onboardable/list/base.rb,
sig/onboardable/list/base.rbs
Overview
The List class manages a sequence of steps in an onboarding process, tracking progress and current state.
Constant Summary collapse
- PROGRESS_CALCULATION =
Default calculation for onboarding progress as a percentage.
->(step_index, steps_size) { (step_index.to_f / steps_size) * 100 }
Instance Attribute Summary collapse
-
#current_step ⇒ Step
The current step in the list.
-
#options ⇒ Hash
The options hash for the list.
-
#steps ⇒ Array<Step>
The steps in the list.
Instance Method Summary collapse
-
#initialize(steps, current_step, options = {}) ⇒ Base
constructor
Initializes a new instance of the List with steps and a current step.
-
#progress(progress_calculation = nil) ⇒ Float
Calculates and returns the onboarding progress as a percentage.
-
#step_error!(step) ⇒ Object
Raises a StepError indicating an invalid step was encountered.
-
#step_index(step) ⇒ Integer
Determines the index of a given step in the list, ensuring the step exists.
-
#update_each_step_status(current_step_index) ⇒ Array<Step>
Updates the status of each step in the list based on the current step index.
Methods included from Navigation
#current_step?, #first_step, #first_step?, #first_step_error!, #last_step, #last_step?, #last_step_error!, #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 the List with steps and a current step.
26 27 28 29 30 |
# File 'lib/onboardable/list/base.rb', line 26 def initialize(steps, current_step, = {}) self.steps = steps self.current_step = current_step self. = end |
Instance Attribute Details
#current_step ⇒ Step
Returns The current step in the list.
17 18 19 |
# File 'lib/onboardable/list/base.rb', line 17 def current_step @current_step end |
#options ⇒ Hash
Returns The options hash for the list.
44 45 46 |
# File 'lib/onboardable/list/base.rb', line 44 def @options end |
#steps ⇒ Array<Step>
Returns The steps in the list.
14 15 16 |
# File 'lib/onboardable/list/base.rb', line 14 def steps @steps end |
Instance Method Details
#progress(progress_calculation = nil) ⇒ Float
Calculates and returns the onboarding progress as a percentage.
36 37 38 39 |
# File 'lib/onboardable/list/base.rb', line 36 def progress(progress_calculation = nil) progress_calculation ||= .fetch(:progress_calculation, PROGRESS_CALCULATION) Float(progress_calculation[step_index(current_step), steps.size]) end |
#step_error!(step) ⇒ Object
Raises a StepError indicating an invalid step was encountered.
97 98 99 |
# File 'lib/onboardable/list/base.rb', line 97 def step_error!(step) raise StepError.new(step.to_str, steps.map(&:to_str)) end |
#step_index(step) ⇒ Integer
Determines the index of a given step in the list, ensuring the step exists.
79 80 81 |
# File 'lib/onboardable/list/base.rb', line 79 def step_index(step) steps.index { |item| item == step } || step_error!(step) end |
#update_each_step_status(current_step_index) ⇒ Array<Step>
Updates the status of each step in the list based on the current step index.
87 88 89 90 91 |
# File 'lib/onboardable/list/base.rb', line 87 def update_each_step_status(current_step_index) steps.each_with_index do |step, index| step.update_status!(index <=> current_step_index) end end |