Module: Lutaml::Xml::Schema::BuiltinTypes

Defined in:
lib/lutaml/xml/schema/builtin_types.rb

Overview

W3C XML Schema 1.1 Part 2: Datatypes www.w3.org/TR/xmlschema11-2/

This module defines all built-in XSD types for validation purposes. Used by XSD generation and validation to identify standard W3C types.

Constant Summary collapse

PRIMITIVE_TYPES =

Primitive types (Section 3.2) These are the fundamental types from which all other types are derived

%w[
  xs:string
  xs:boolean
  xs:decimal
  xs:float
  xs:double
  xs:duration
  xs:dateTime
  xs:time
  xs:date
  xs:gYearMonth
  xs:gYear
  xs:gMonthDay
  xs:gDay
  xs:gMonth
  xs:hexBinary
  xs:base64Binary
  xs:anyURI
  xs:QName
  xs:NOTATION
].freeze
DERIVED_TYPES =

Derived types (Section 3.3) These are built from primitive types with restrictions

%w[
  xs:normalizedString
  xs:token
  xs:language
  xs:NMTOKEN
  xs:NMTOKENS
  xs:Name
  xs:NCName
  xs:ID
  xs:IDREF
  xs:IDREFS
  xs:ENTITY
  xs:ENTITIES
  xs:integer
  xs:nonPositiveInteger
  xs:negativeInteger
  xs:long
  xs:int
  xs:short
  xs:byte
  xs:nonNegativeInteger
  xs:unsignedLong
  xs:unsignedInt
  xs:unsignedShort
  xs:unsignedByte
  xs:positiveInteger
  xs:yearMonthDuration
  xs:dayTimeDuration
  xs:dateTimeStamp
].freeze
SPECIAL_TYPES =

Special types xs:anyType - The root of the type hierarchy xs:anySimpleType - The base type for all simple types

%w[
  xs:anyType
  xs:anySimpleType
].freeze
ALL_TYPES =

All built-in types

(PRIMITIVE_TYPES + DERIVED_TYPES + SPECIAL_TYPES).freeze

Class Method Summary collapse

Class Method Details

.builtin?(type_name) ⇒ Boolean

Check if a type name is a W3C XML Schema built-in type

Examples:

BuiltinTypes.builtin?("xs:string")  #=> true
BuiltinTypes.builtin?("xs:integer") #=> true
BuiltinTypes.builtin?("CustomType") #=> false

Parameters:

  • type_name (String)

    The XSD type name to check (e.g., “xs:string”)

Returns:

  • (Boolean)

    true if the type is a standard W3C built-in type



89
90
91
# File 'lib/lutaml/xml/schema/builtin_types.rb', line 89

def self.builtin?(type_name)
  ALL_TYPES.include?(type_name)
end

.category(type_name) ⇒ Symbol?

Get the category of a built-in type

Examples:

BuiltinTypes.category("xs:string")  #=> :primitive
BuiltinTypes.category("xs:integer") #=> :derived
BuiltinTypes.category("CustomType") #=> nil

Parameters:

  • type_name (String)

    The XSD type name

Returns:

  • (Symbol, nil)

    :primitive, :derived, :special, or nil if not built-in



102
103
104
105
106
107
108
# File 'lib/lutaml/xml/schema/builtin_types.rb', line 102

def self.category(type_name)
  return :primitive if PRIMITIVE_TYPES.include?(type_name)
  return :derived if DERIVED_TYPES.include?(type_name)
  return :special if SPECIAL_TYPES.include?(type_name)

  nil
end