Class: Lutaml::Model::ModelMappingRule
- Inherits:
-
Object
- Object
- Lutaml::Model::ModelMappingRule
- Defined in:
- lib/lutaml/model/mapping/model_mapping_rule.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(name = nil, from:, to:, transform: nil, reverse_transform: nil, collection: false, mapping: nil) ⇒ ModelMappingRule
constructor
A new instance of ModelMappingRule.
- #transform_value(transformer, attr, value, reverse: false) ⇒ Object
Constructor Details
#initialize(name = nil, from:, to:, transform: nil, reverse_transform: nil, collection: false, mapping: nil) ⇒ ModelMappingRule
Returns a new instance of ModelMappingRule.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lutaml/model/mapping/model_mapping_rule.rb', line 10 def initialize( name = nil, from:, to:, transform: nil, reverse_transform: nil, collection: false, mapping: nil ) @name = name @from = from @to = to @transform = transform @reverse_transform = transform.is_a?(Class) && reverse_transform.nil? ? transform : reverse_transform @collection = collection @mapping = mapping end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
4 5 6 |
# File 'lib/lutaml/model/mapping/model_mapping_rule.rb', line 4 def collection @collection end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/lutaml/model/mapping/model_mapping_rule.rb', line 4 def from @from end |
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
4 5 6 |
# File 'lib/lutaml/model/mapping/model_mapping_rule.rb', line 4 def mapping @mapping end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/lutaml/model/mapping/model_mapping_rule.rb', line 4 def name @name end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
4 5 6 |
# File 'lib/lutaml/model/mapping/model_mapping_rule.rb', line 4 def to @to end |
Instance Method Details
#transform_value(transformer, attr, value, reverse: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lutaml/model/mapping/model_mapping_rule.rb', line 28 def transform_value(transformer, attr, value, reverse: false) if @mapping return @mapping.process_mappings(value, reverse: reverse) end if @reverse_transform && reverse transform_call(transformer, @reverse_transform, value, :reverse_transform) elsif @transform transform_call(transformer, @transform, value, :transform) else attr.type.cast(value) end end |