Class: WorkflowTemplate::State::Normalizer
- Inherits:
-
Object
- Object
- WorkflowTemplate::State::Normalizer
- Defined in:
- lib/workflow_template/state/normalizer.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(keys) ⇒ Normalizer
constructor
A new instance of Normalizer.
- #normalize(hash) ⇒ Object
Constructor Details
#initialize(keys) ⇒ Normalizer
Returns a new instance of Normalizer.
8 9 10 11 |
# File 'lib/workflow_template/state/normalizer.rb', line 8 def initialize(keys) @keys = keys&.map(&:to_sym).freeze freeze end |
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
6 7 8 |
# File 'lib/workflow_template/state/normalizer.rb', line 6 def keys @keys end |
Class Method Details
.instance(keys = nil) ⇒ Object
23 24 25 26 27 |
# File 'lib/workflow_template/state/normalizer.rb', line 23 def self.instance(keys = nil) return null_object if keys.nil? new keys end |
.null_object ⇒ Object
29 30 31 |
# File 'lib/workflow_template/state/normalizer.rb', line 29 def self.null_object @null_object ||= new(nil) end |
Instance Method Details
#normalize(hash) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/workflow_template/state/normalizer.rb', line 13 def normalize(hash) return hash if keys.nil? keys.each_with_object({}) do |key, normalized| normalized[key] = hash[key] end.freeze end |