Class: XSD::SimpleType

Inherits:
BaseObject show all
Includes:
Named
Defined in:
lib/xsd/objects/simple_type.rb

Overview

The simpleType element defines a simple type and specifies the constraints and information about the values of attributes or text-only elements. Parent elements: attribute, element, list, restriction, schema, union www.w3schools.com/xml/el_simpletype.asp

Constant Summary

Constants inherited from BaseObject

BaseObject::NO_ATTRIBUTES_CONTAINER, BaseObject::NO_ELEMENTS_CONTAINER, BaseObject::XML_SCHEMA

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#id, #options

Instance Method Summary collapse

Methods included from Named

#absolute_name, #namespace

Methods inherited from BaseObject

#[], #collect_attributes, #collect_elements, #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

#listObject

Nested list

Returns:

  • List, nil



30
# File 'lib/xsd/objects/simple_type.rb', line 30

child :list, :list

#nameObject

Specifies a name for the element. This attribute is required if the simpleType element is a child of the schema element, otherwise it is not allowed

Returns:

  • String, nil



15
# File 'lib/xsd/objects/simple_type.rb', line 15

property :name, :string

#restrictionObject

Nested restriction

Returns:

  • Restriction, nil



20
# File 'lib/xsd/objects/simple_type.rb', line 20

child :restriction, :restriction

#unionObject

Nested union

Returns:

  • Union, nil



25
# File 'lib/xsd/objects/simple_type.rb', line 25

child :union, :union

Instance Method Details

#data_typeObject

Get base data type

Returns:

  • String, nil



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/xsd/objects/simple_type.rb', line 40

def data_type
  if restriction
    if restriction.base
      restriction.base_simple_type&.data_type || strip_prefix(restriction.base)
    else
      restriction.simple_type&.data_type
    end
  elsif union
    types = union.types.map { |type| type.is_a?(String) ? strip_prefix(type) : type.data_type }.uniq
    types.size == 1 ? types.first : types
  else
    # list is always a sting
    'string'
  end
end

#linked?Boolean

Determine if this is a linked type

Returns:

  • (Boolean)

    Boolean



34
35
36
# File 'lib/xsd/objects/simple_type.rb', line 34

def linked?
  !name.nil?
end