Class: Lutaml::Xml::Schema::Xsd::Schema
- Inherits:
-
Base
- Object
- Model::Serializable
- Base
- Lutaml::Xml::Schema::Xsd::Schema
- Defined in:
- lib/lutaml/xml/schema/xsd/schema.rb
Constant Summary
Constants inherited from Base
Base::ELEMENT_ORDER_IGNORABLE, Base::XML_DECLARATION_REGEX
Constants included from Model::Serialize
Model::Serialize::DEFAULT_VALUE_MAP, Model::Serialize::INTERNAL_ATTRIBUTES, Model::Serialize::LAZY_EMPTY_COLLECTION
Instance Attribute Summary
Attributes included from Model::Serialize
#lutaml_parent, #lutaml_register, #lutaml_root
Class Method Summary collapse
- .add_in_progress(location) ⇒ Object
- .in_progress ⇒ Object
- .in_progress?(location) ⇒ Boolean
- .processed_schemas ⇒ Object
- .remove_in_progress(location) ⇒ Object
- .reset_processed_schemas ⇒ Object
- .schema_processed(location, schema) ⇒ Object
- .schema_processed?(location) ⇒ Boolean
Instance Method Summary collapse
-
#attribute_groups_sorted_by_name ⇒ Object
Return attribute groups sorted alphabetically by name.
-
#attributes_sorted_by_name ⇒ Object
Return global attributes sorted alphabetically by name.
-
#complex_types_sorted_by_name ⇒ Object
Return complex types sorted alphabetically by name.
-
#elements_sorted_by_name ⇒ Object
Return global elements sorted alphabetically by name for stable Liquid iteration.
-
#find_complex_type(name) ⇒ ComplexType?
Find complex type by name.
-
#find_element(local_name) ⇒ Element?
Find an element definition by local name.
-
#find_simple_type(name) ⇒ SimpleType?
Find simple type by name.
-
#find_type(local_name) ⇒ SimpleType, ...
Find a type definition by local name.
- #import_from_schema(model, value) ⇒ Object
- #import_to_schema(model, parent, _doc) ⇒ Object
- #include_from_schema(model, value) ⇒ Object
- #include_to_schema(model, parent, _doc) ⇒ Object
-
#name ⇒ String?
Get a human-readable name for the schema.
-
#simple_types_sorted_by_name ⇒ Object
Return simple types sorted alphabetically by name.
-
#stats ⇒ Hash
Quick statistics about the schema.
-
#summary ⇒ String
Human-readable summary.
- #target_namespace_from(model, value) ⇒ Object
-
#valid? ⇒ Boolean
Quick validation check.
Methods inherited from Base
#all?, #annotation?, #any?, #assign_root!, #attribute?, #attribute_group?, #choice?, #complex_content?, #element?, #max_occurrences, #min_occurrences, #resolved_element_order, #sequence?, #simple_content?, #target_prefix, #to_formatted_xml, #unresolvable_items
Methods included from Model::Serialize
#attr_value, #attribute_exist?, #extract_register_id, included, #init_deserialization_state, #initialize, #key_exist?, #key_value, #method_missing, #prepare_instance_format_options, #pretty_print_instance_variables, register_format_mapping_method, register_from_format_method, register_to_format_method, #respond_to_missing?, #to_format, #to_yaml_hash, #using_default?, #using_default_for, #validate_attribute!, #validate_root_mapping!, #value_map, #value_set_for
Methods included from Model::Liquefiable
Methods included from Model::Validation
#format_element_sequences, new_registry, #order_names, #validate, validate, #validate!, validate!, #validate_helper, #validate_sequence!
Methods included from Model::ComparableModel
#already_compared?, #attributes_hash, #calculate_hash, #comparison_key, #eql?, #hash, included, #same_class?
Methods included from Model::Serialize::Builder
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Lutaml::Model::Serialize
Class Method Details
.add_in_progress(location) ⇒ Object
362 363 364 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 362 def add_in_progress(location) in_progress << location end |
.in_progress ⇒ Object
354 355 356 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 354 def in_progress @in_progress ||= [] end |
.in_progress?(location) ⇒ Boolean
358 359 360 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 358 def in_progress?(location) in_progress.include?(location) end |
.processed_schemas ⇒ Object
340 341 342 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 340 def processed_schemas @processed_schemas ||= {} end |
.remove_in_progress(location) ⇒ Object
366 367 368 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 366 def remove_in_progress(location) in_progress.delete(location) end |
.reset_processed_schemas ⇒ Object
336 337 338 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 336 def reset_processed_schemas @processed_schemas = {} end |
.schema_processed(location, schema) ⇒ Object
348 349 350 351 352 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 348 def schema_processed(location, schema) return if location.nil? processed_schemas[location] = schema end |
.schema_processed?(location) ⇒ Boolean
344 345 346 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 344 def schema_processed?(location) processed_schemas[location] end |
Instance Method Details
#attribute_groups_sorted_by_name ⇒ Object
Return attribute groups sorted alphabetically by name.
144 145 146 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 144 def attribute_groups_sorted_by_name attribute_group.sort_by { |item| item.name.to_s } end |
#attributes_sorted_by_name ⇒ Object
Return global attributes sorted alphabetically by name.
129 130 131 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 129 def attributes_sorted_by_name attribute.sort_by { |item| item.name.to_s } end |
#complex_types_sorted_by_name ⇒ Object
Return complex types sorted alphabetically by name.
139 140 141 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 139 def complex_types_sorted_by_name complex_type.sort_by { |item| item.name.to_s } end |
#elements_sorted_by_name ⇒ Object
Return global elements sorted alphabetically by name for stable Liquid iteration.
124 125 126 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 124 def elements_sorted_by_name element.sort_by { |item| item.name.to_s } end |
#find_complex_type(name) ⇒ ComplexType?
Find complex type by name
180 181 182 183 184 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 180 def find_complex_type(name) return nil if name.nil? complex_type.find { |type| type.name == name } end |
#find_element(local_name) ⇒ Element?
Find an element definition by local name
171 172 173 174 175 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 171 def find_element(local_name) return nil if local_name.nil? element.find { |element| element.name == local_name } end |
#find_simple_type(name) ⇒ SimpleType?
Find simple type by name
189 190 191 192 193 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 189 def find_simple_type(name) return nil if name.nil? simple_type.find { |type| type.name == name } end |
#find_type(local_name) ⇒ SimpleType, ...
Find a type definition by local name
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 157 def find_type(local_name) return nil if local_name.nil? # Search simple types first. found = simple_type.find { |type| type.name == local_name } return found if found # Fall back to complex types if no simple type matches. complex_type.find { |type| type.name == local_name } end |
#import_from_schema(model, value) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 83 def import_from_schema(model, value) value.each do |schema| setup_import_and_include( "import", model, schema, namespace: schema.attributes["namespace"].value, ) end end |
#import_to_schema(model, parent, _doc) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 94 def import_to_schema(model, parent, _doc) return if model.imported model.imported = true model.imports.each do |imported_schema| parent.add_child(imported_schema.to_xml) end end |
#include_from_schema(model, value) ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 103 def include_from_schema(model, value) value.each do |schema| setup_import_and_include( "include", model, schema, ) end end |
#include_to_schema(model, parent, _doc) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 113 def include_to_schema(model, parent, _doc) return if model.included model.included = true model.includes.each do |schema_hash| parent.add_child(schema_hash.to_xml) end end |
#name ⇒ String?
Get a human-readable name for the schema
229 230 231 232 233 234 235 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 229 def name return nil unless target_namespace # Extract the last segment of the namespace URI as the schema name. # For example, "http://example.com/test" becomes "test". target_namespace.split("/").last || target_namespace end |
#simple_types_sorted_by_name ⇒ Object
Return simple types sorted alphabetically by name.
134 135 136 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 134 def simple_types_sorted_by_name simple_type.sort_by { |item| item.name.to_s } end |
#stats ⇒ Hash
Quick statistics about the schema
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 197 def stats { elements: element.size, complex_types: complex_type.size, simple_types: simple_type.size, attributes: attribute.size, groups: group.size, attribute_groups: attribute_group.size, imports: import.size, includes: include.size, namespaces: all_namespaces.size, } end |
#summary ⇒ String
Human-readable summary
220 221 222 223 224 225 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 220 def summary ns = target_namespace || "(no namespace)" "#{ns}: #{stats[:elements]} elements, " \ "#{stats[:complex_types]} complex types, " \ "#{stats[:simple_types]} simple types" end |
#target_namespace_from(model, value) ⇒ Object
148 149 150 151 152 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 148 def target_namespace_from(model, value) model.target_namespace = value model.target_namespace_prefix = namespace_prefix_for(model.pending_plan_root_element, value) end |
#valid? ⇒ Boolean
Quick validation check
213 214 215 216 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 213 def valid? # Basic validation: a parsed schema should declare a target namespace. !target_namespace.nil? && !target_namespace.empty? end |