Class: XSD::Restriction

Inherits:
BaseObject show all
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 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

Instance Attribute Summary collapse

Attributes included from AttributeContainer

#attribute_groups, #attributes

Attributes included from SimpleTyped

#simple_type

Attributes included from Based

#base, #base_complex_type, #base_simple_type

Attributes inherited from BaseObject

#id, #options

Instance Method Summary collapse

Methods included from AttributeContainer

included

Methods included from SimpleTyped

included

Methods included from Based

included

Methods inherited from BaseObject

#[], #documentation, #documentation_for, #get_prefix, #initialize, #inspect, #map_child, #map_children, #namespaces, #node, #node_to_object, #nodes, #object_by_name, #parent, #reader, #schema, #schemas_for_namespace, #strip_prefix

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

#allObject

Nested all

Returns:

  • All



27
# File 'lib/xsd/objects/restriction.rb', line 27

child :all, :all

#choiceObject

Nested choice

Returns:

  • Choice



32
# File 'lib/xsd/objects/restriction.rb', line 32

child :choice, :choice

#groupObject

Nested group

Returns:

  • Group



22
# File 'lib/xsd/objects/restriction.rb', line 22

child :group, :group

#sequenceObject

Nested sequence

Returns:

  • 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

Parameters:

  • include_base (Boolean) (defaults to: true)


73
74
75
76
77
# File 'lib/xsd/objects/restriction.rb', line 73

def collect_attributes(include_base = true)
  result = super(include_base)
  # Filter restricted attributes to avoid duplicates from restricting and restricted type
  include_base ? result.inject({}) { |hash, item| hash[item.name] = item; hash }.values : result
end

#collect_elements(include_base = false) ⇒ Object

Get all available elements on the current stack level, optionally including base type elements

Parameters:

  • include_base (Boolean) (defaults to: false)


64
65
66
67
68
# File 'lib/xsd/objects/restriction.rb', line 64

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

#facetsObject

Get restriction facets

Returns:

  • Hash



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/xsd/objects/restriction.rb', line 41

def facets
  nodes.inject({}) do |hash, node|
    if FACET_ELEMENTS.include?(node.name)
      key   = node.name
      value = node['value']

      if key == 'enumeration'
        hash[key]        ||= {}
        hash[key][value] = documentation_for(node)
      elsif key == 'pattern'
        hash[key] ||= []
        hash[key].push(value)
      else
        hash[key] = value
      end
    end
    hash
  end
end