Class: WorkflowTemplate::State::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow_template/state/normalizer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#keysObject (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_objectObject



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