Class: Holotype::ValueNormalizer
- Inherits:
-
Object
- Object
- Holotype::ValueNormalizer
- Defined in:
- lib/holotype/value_normalizer.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
-
#initialize(definition) ⇒ ValueNormalizer
constructor
A new instance of ValueNormalizer.
- #normalize(value) ⇒ Object
Constructor Details
#initialize(definition) ⇒ ValueNormalizer
Returns a new instance of ValueNormalizer.
5 6 7 |
# File 'lib/holotype/value_normalizer.rb', line 5 def initialize definition @definition = definition end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
3 4 5 |
# File 'lib/holotype/value_normalizer.rb', line 3 def definition @definition end |
Instance Method Details
#normalize(value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/holotype/value_normalizer.rb', line 9 def normalize value result = if definition.has_value_class? if value.nil? nil else definition.value_class.new(**value) end else value end if definition.immutable? result.freeze else result end end |