Class: XSD::Attribute

Inherits:
BaseObject show all
Includes:
Named, Referenced, SimpleTyped
Defined in:
lib/xsd/objects/attribute.rb

Overview

The attribute element defines an attribute. Parent elements: attributeGroup, schema, complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent) www.w3schools.com/xml/el_attribute.asp

Constant Summary collapse

TYPE_PROPERTY =
:type

Constants inherited from BaseObject

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

Instance Attribute Summary collapse

Attributes included from Referenced

#ref, #reference

Attributes included from SimpleTyped

#simple_type

Attributes inherited from BaseObject

#id, #options

Instance Method Summary collapse

Methods included from Named

#absolute_name, #namespace

Methods included from Referenced

included, #referenced?

Methods included from SimpleTyped

included

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

#defaultObject

Optional. Specifies a default value for the attribute. Default and fixed attributes cannot both be present

Returns:

  • String, nil



23
# File 'lib/xsd/objects/attribute.rb', line 23

property :default, :string

#fixedObject

Optional. Specifies a fixed value for the attribute. Default and fixed attributes cannot both be present

Returns:

  • String, nil



28
# File 'lib/xsd/objects/attribute.rb', line 28

property :fixed, :string

#formObject

Optional. Specifies the form for the attribute. The default value is the value of the attributeFormDefault attribute of the schema containing the attribute. Can be set to one of the following:

qualified   - indicates that this attribute must be qualified with the namespace prefix and the no-colon-name
              (NCName) of the attribute
unqualified - indicates that this attribute is not required to be qualified with the namespace prefix and is
              matched against the (NCName) of the attribute

Returns:

  • String



38
# File 'lib/xsd/objects/attribute.rb', line 38

property :form, :string, default: proc { schema.attribute_form_default }

#nameObject

Optional. Specifies the name of the attribute. Name and ref attributes cannot both be present

Returns:

  • String, nil



18
# File 'lib/xsd/objects/attribute.rb', line 18

property :name, :string

#typeObject

Optional. Specifies a built-in data type or a simple type. The type attribute can only be present when the content does not contain a simpleType element

Returns:

  • String, nil



44
# File 'lib/xsd/objects/attribute.rb', line 44

property :type, :string

#useObject

Optional. Specifies how the attribute is used. Can be one of the following values:

optional   - the attribute is optional (this is default)
prohibited - the attribute cannot be used
required   - the attribute is required

Returns:

  • String



52
# File 'lib/xsd/objects/attribute.rb', line 52

property :use, :string, default: 'optional'

Instance Method Details

#data_typeObject

Get base data type

Returns:

  • String, nil



74
75
76
77
78
79
80
# File 'lib/xsd/objects/attribute.rb', line 74

def data_type
  if simple_type
    simple_type.data_type
  else
    strip_prefix(type)
  end
end

#optional?Boolean

Determine if attribute is optional

Returns:

  • (Boolean)

    Boolean



62
63
64
# File 'lib/xsd/objects/attribute.rb', line 62

def optional?
  use == 'optional'
end

#prohibited?Boolean

Determine if attribute is prohibited

Returns:

  • (Boolean)

    Boolean



68
69
70
# File 'lib/xsd/objects/attribute.rb', line 68

def prohibited?
  use == 'prohibited'
end

#required?Boolean

Determine if attribute is required

Returns:

  • (Boolean)

    Boolean



56
57
58
# File 'lib/xsd/objects/attribute.rb', line 56

def required?
  use == 'required'
end