Class: Lutaml::Model::Xml::MappingRule
- Inherits:
-
MappingRule
- Object
- MappingRule
- Lutaml::Model::Xml::MappingRule
- Defined in:
- lib/lutaml/model/xml/mapping_rule.rb
Constant Summary
Constants inherited from MappingRule
Instance Attribute Summary collapse
-
#cdata ⇒ Object
readonly
Returns the value of attribute cdata.
-
#default_namespace ⇒ Object
readonly
Returns the value of attribute default_namespace.
-
#mixed_content ⇒ Object
readonly
Returns the value of attribute mixed_content.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Attributes inherited from MappingRule
#as_attribute, #attribute, #custom_methods, #delegate, #format, #name, #polymorphic, #polymorphic_map, #render_default, #render_empty, #render_nil, #to, #to_instance, #transform, #treat_empty, #treat_nil, #treat_omitted
Instance Method Summary collapse
- #castable? ⇒ Boolean
- #content_key ⇒ Object
- #content_mapping? ⇒ Boolean
- #deep_dup ⇒ Object
-
#initialize(name, to:, render_nil: false, render_default: false, render_empty: false, treat_nil: nil, treat_empty: nil, treat_omitted: nil, with: {}, delegate: nil, namespace: nil, prefix: nil, mixed_content: false, cdata: false, namespace_set: false, prefix_set: false, attribute: false, default_namespace: nil, polymorphic: {}, polymorphic_map: {}, transform: {}, value_map: {}) ⇒ MappingRule
constructor
A new instance of MappingRule.
- #mixed_content? ⇒ Boolean
- #namespace_set? ⇒ Boolean
- #namespaced_name(parent_namespace = nil, name = self.name) ⇒ Object
- #namespaced_names(parent_namespace = nil) ⇒ Object
- #prefix_set? ⇒ Boolean
- #prefixed_name ⇒ Object
Methods inherited from MappingRule
#default_value_map, #deserialize, #eql?, #has_custom_method_for_deserialization?, #has_custom_method_for_serialization?, #multiple_mappings?, #polymorphic_mapping?, #raw_mapping?, #render?, #render_as, #render_empty?, #render_nil?, #render_omitted?, #render_value_for, #serialize, #serialize_attribute, #to_value_for, #treat?, #treat_as, #treat_empty?, #treat_nil?, #treat_omitted?, #value_for_option, #value_map
Constructor Details
#initialize(name, to:, render_nil: false, render_default: false, render_empty: false, treat_nil: nil, treat_empty: nil, treat_omitted: nil, with: {}, delegate: nil, namespace: nil, prefix: nil, mixed_content: false, cdata: false, namespace_set: false, prefix_set: false, attribute: false, default_namespace: nil, polymorphic: {}, polymorphic_map: {}, transform: {}, value_map: {}) ⇒ MappingRule
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 13 def initialize( name, to:, render_nil: false, render_default: false, render_empty: false, treat_nil: nil, treat_empty: nil, treat_omitted: nil, with: {}, delegate: nil, namespace: nil, prefix: nil, mixed_content: false, cdata: false, namespace_set: false, prefix_set: false, attribute: false, default_namespace: nil, polymorphic: {}, polymorphic_map: {}, transform: {}, value_map: {} ) super( name, to: to, render_nil: render_nil, render_default: render_default, render_empty: render_empty, treat_nil: treat_nil, treat_empty: treat_empty, treat_omitted: treat_omitted, with: with, delegate: delegate, attribute: attribute, polymorphic: polymorphic, polymorphic_map: polymorphic_map, transform: transform, value_map: value_map, ) @namespace = if namespace.to_s == "inherit" # we are using inherit_namespace in xml builder by # default so no need to do anything here. else namespace end @prefix = prefix @mixed_content = mixed_content @cdata = cdata @default_namespace = default_namespace @namespace_set = namespace_set @prefix_set = prefix_set end |
Instance Attribute Details
#cdata ⇒ Object (readonly)
Returns the value of attribute cdata.
7 8 9 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 7 def cdata @cdata end |
#default_namespace ⇒ Object (readonly)
Returns the value of attribute default_namespace.
7 8 9 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 7 def default_namespace @default_namespace end |
#mixed_content ⇒ Object (readonly)
Returns the value of attribute mixed_content.
7 8 9 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 7 def mixed_content @mixed_content end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 7 def namespace @namespace end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 7 def prefix @prefix end |
Instance Method Details
#castable? ⇒ Boolean
87 88 89 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 87 def castable? !raw_mapping? && !content_mapping? && !custom_methods[:from] end |
#content_key ⇒ Object
83 84 85 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 83 def content_key cdata ? "#cdata-section" : "text" end |
#content_mapping? ⇒ Boolean
79 80 81 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 79 def content_mapping? name.nil? end |
#deep_dup ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 124 def deep_dup self.class.new( name.dup, to: to, render_nil: render_nil, render_default: render_default, with: Utils.deep_dup(custom_methods), delegate: delegate, namespace: namespace.dup, prefix: prefix.dup, mixed_content: mixed_content, cdata: cdata, namespace_set: namespace_set?, prefix_set: prefix_set?, attribute: attribute, polymorphic: polymorphic.dup, default_namespace: default_namespace.dup, transform: transform.dup, render_empty: render_empty.dup, value_map: Utils.deep_dup(@value_map), ) end |
#mixed_content? ⇒ Boolean
91 92 93 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 91 def mixed_content? !!@mixed_content end |
#namespace_set? ⇒ Boolean
71 72 73 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 71 def namespace_set? !!@namespace_set end |
#namespaced_name(parent_namespace = nil, name = self.name) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 112 def namespaced_name(parent_namespace = nil, name = self.name) if name.to_s == "lang" Utils.blank?(prefix) ? name.to_s : "#{prefix}:#{name}" elsif namespace_set? || @attribute [namespace, name].compact.join(":") elsif default_namespace "#{default_namespace}:#{name}" else [parent_namespace, name].compact.join(":") end end |
#namespaced_names(parent_namespace = nil) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 104 def namespaced_names(parent_namespace = nil) if multiple_mappings? name.map { |rule_name| namespaced_name(parent_namespace, rule_name) } else [namespaced_name(parent_namespace)] end end |
#prefix_set? ⇒ Boolean
75 76 77 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 75 def prefix_set? !!@prefix_set end |
#prefixed_name ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/lutaml/model/xml/mapping_rule.rb', line 95 def prefixed_name rule_name = multiple_mappings? ? name.first : name if prefix "#{prefix}:#{rule_name}" else rule_name end end |