Class: XSD::Restriction
- Inherits:
-
BaseObject
- Object
- BaseObject
- XSD::Restriction
- Includes:
- AttributeContainer, Based, SimpleTyped
- Defined in:
- lib/xsd/objects/restriction.rb
Overview
The restriction element defines restrictions on a simpleType, simpleContent, or complexContent definition. Parent elements: simpleType, simpleContent, complexContent https://www.w3schools.com/xml/el_restriction.asp
Constant Summary collapse
- TYPE_PROPERTY =
nil- FACET_ELEMENTS =
%w[ minExclusive minInclusive maxExclusive maxInclusive totalDigits fractionDigits length minLength maxLength enumeration whiteSpace pattern ].freeze
Constants inherited from BaseObject
BaseObject::NO_ATTRIBUTES_CONTAINER, BaseObject::NO_ELEMENTS_CONTAINER, BaseObject::XML_SCHEMA, BaseObject::XML_SCHEMA_NS
Instance Attribute Summary collapse
-
#all ⇒ Object
Nested all.
-
#choice ⇒ Object
Nested choice.
-
#group ⇒ Object
Nested group.
-
#sequence ⇒ Object
Nested sequence.
Attributes included from AttributeContainer
#attribute_groups, #attributes
Attributes included from SimpleTyped
Attributes included from Based
#base, #base_complex_type, #base_simple_type
Attributes inherited from BaseObject
Instance Method Summary collapse
-
#collect_attributes(include_base = true) ⇒ Object
Get all available attributes on the current stack level, optionally including base type attributes.
-
#collect_elements(include_base = false) ⇒ Object
Get all available elements on the current stack level, optionally including base type elements.
-
#facets ⇒ Object
Get restriction facets.
Methods included from AttributeContainer
Methods included from SimpleTyped
Methods included from Based
Methods inherited from BaseObject
#[], child, #documentation, #documentation_for, #get_prefix, #initialize, #inspect, link, #map_child, #map_children, mapped_name, #namespaces, #node, #node_to_object, #nodes, #object_by_name, #parent, property, #reader, #schema, #schemas_for_namespace, #strip_prefix, to_underscore
Constructor Details
This class inherits a constructor from XSD::BaseObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class XSD::BaseObject
Instance Attribute Details
#all ⇒ Object
Nested all
27 |
# File 'lib/xsd/objects/restriction.rb', line 27 child :all, :all |
#choice ⇒ Object
Nested choice
32 |
# File 'lib/xsd/objects/restriction.rb', line 32 child :choice, :choice |
#group ⇒ Object
Nested group
22 |
# File 'lib/xsd/objects/restriction.rb', line 22 child :group, :group |
#sequence ⇒ Object
Nested sequence
37 |
# File 'lib/xsd/objects/restriction.rb', line 37 child :sequence, :sequence |
Instance Method Details
#collect_attributes(include_base = true) ⇒ Object
Get all available attributes on the current stack level, optionally including base type attributes
71 72 73 74 75 |
# File 'lib/xsd/objects/restriction.rb', line 71 def collect_attributes(include_base = true) result = super(include_base) # Filter restricted attributes to avoid duplicates from restricting and restricted type include_base ? result.to_h { |item| [item.name, item] }.values : result end |
#collect_elements(include_base = false) ⇒ Object
Get all available elements on the current stack level, optionally including base type elements
62 63 64 65 66 |
# File 'lib/xsd/objects/restriction.rb', line 62 def collect_elements(include_base = false) # Don't include elements from base by default, that will lead to element duplicates because # elements in complex restriction MUST be all listen in restricting type super(include_base) end |
#facets ⇒ Object
Get restriction facets
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/xsd/objects/restriction.rb', line 41 def facets @facets ||= nodes.each_with_object({}) do |node, hash| next unless FACET_ELEMENTS.include?(node.name) key = node.name value = node['value'] case key when 'enumeration' (hash[key] ||= {})[value] = documentation_for(node) when 'pattern' (hash[key] ||= []).push(value) else hash[key] = value end end end |