Class: Onboardable::Step
- Inherits:
-
Object
- Object
- Onboardable::Step
- Defined in:
- lib/onboardable/step.rb
Overview
Represents a single step within an onboarding process, including its status and associated data.
Constant Summary collapse
- CONVERSION_METHOD =
:to_onboarding_step
- PENDING_STATUS =
:pending
- CURRENT_STATUS =
:current
- COMPLETED_STATUS =
:completed
- DEFAULT_STATUS =
PENDING_STATUS
- STATUSES =
[PENDING_STATUS, CURRENT_STATUS, COMPLETED_STATUS].freeze
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Custom data associated with the step.
-
#name ⇒ String
readonly
The name of the step.
-
#status ⇒ Symbol
readonly
The current status of the step.
Class Method Summary collapse
-
.try_convert(klass) ⇒ Step?
Attempts to convert a class to a Step object using a specified conversion method.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this step to another to determine if they are equivalent, based on the step name.
-
#completed? ⇒ Boolean
Checks if the step is in the completed status.
-
#current? ⇒ Boolean
Checks if the step is in the current status.
-
#initialize(name, data = {}) ⇒ Step
constructor
Initializes a new Step with a name, optional custom data, and a default status.
-
#pending? ⇒ Boolean
Checks if the step is in the pending status.
-
#to_str ⇒ String
Provides a string representation of the step, using its name.
-
#update_status!(comparison_result) ⇒ Symbol
Updates the status of the step based on a specified comparison result.
Constructor Details
#initialize(name, data = {}) ⇒ Step
Initializes a new Step with a name, optional custom data, and a default status.
53 54 55 56 57 |
# File 'lib/onboardable/step.rb', line 53 def initialize(name, data = {}) self.name = name self.data = data self.status = DEFAULT_STATUS end |
Instance Attribute Details
#data ⇒ Hash
Returns Custom data associated with the step.
44 45 46 |
# File 'lib/onboardable/step.rb', line 44 def data @data end |
#name ⇒ String
Returns The name of the step.
41 42 43 |
# File 'lib/onboardable/step.rb', line 41 def name @name end |
#status ⇒ Symbol
Returns The current status of the step.
47 48 49 |
# File 'lib/onboardable/step.rb', line 47 def status @status end |
Class Method Details
.try_convert(klass) ⇒ Step?
Attempts to convert a class to a Step object using a specified conversion method.
21 22 23 24 25 26 27 |
# File 'lib/onboardable/step.rb', line 21 def try_convert(klass) return unless klass.respond_to?(CONVERSION_METHOD) klass.public_send(CONVERSION_METHOD).then do |step| step.is_a?(Step) ? step : conversion_error!(klass, step) end end |
Instance Method Details
#==(other) ⇒ Boolean
Compares this step to another to determine if they are equivalent, based on the step name.
84 85 86 |
# File 'lib/onboardable/step.rb', line 84 def ==(other) to_str == other.to_str end |
#completed? ⇒ Boolean
Checks if the step is in the completed status.
76 77 78 |
# File 'lib/onboardable/step.rb', line 76 def completed? status == COMPLETED_STATUS end |
#current? ⇒ Boolean
Checks if the step is in the current status.
69 70 71 |
# File 'lib/onboardable/step.rb', line 69 def current? status == CURRENT_STATUS end |
#pending? ⇒ Boolean
Checks if the step is in the pending status.
62 63 64 |
# File 'lib/onboardable/step.rb', line 62 def pending? status == PENDING_STATUS end |
#to_str ⇒ String
Provides a string representation of the step, using its name.
91 92 93 |
# File 'lib/onboardable/step.rb', line 91 def to_str name end |
#update_status!(comparison_result) ⇒ Symbol
Updates the status of the step based on a specified comparison result.
99 100 101 102 103 104 105 |
# File 'lib/onboardable/step.rb', line 99 def update_status!(comparison_result) self.status = case comparison_result when -1 then COMPLETED_STATUS when 0 then CURRENT_STATUS when 1 then PENDING_STATUS else comparison_result_error!(comparison_result); end end |