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, custom_args = {}) ⇒ Object
Capture both the target namespace URI and the matching prefix discovered during XML deserialization.
-
#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, #order_names, #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
359 360 361 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 359 def add_in_progress(location) in_progress << location end |
.in_progress ⇒ Object
351 352 353 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 351 def in_progress @in_progress ||= [] end |
.in_progress?(location) ⇒ Boolean
355 356 357 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 355 def in_progress?(location) in_progress.include?(location) end |
.processed_schemas ⇒ Object
337 338 339 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 337 def processed_schemas @processed_schemas ||= {} end |
.remove_in_progress(location) ⇒ Object
363 364 365 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 363 def remove_in_progress(location) in_progress.delete(location) end |
.reset_processed_schemas ⇒ Object
333 334 335 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 333 def reset_processed_schemas @processed_schemas = {} end |
.schema_processed(location, schema) ⇒ Object
345 346 347 348 349 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 345 def schema_processed(location, schema) return if location.nil? processed_schemas[location] = schema end |
.schema_processed?(location) ⇒ Boolean
341 342 343 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 341 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
183 184 185 186 187 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 183 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
174 175 176 177 178 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 174 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
192 193 194 195 196 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 192 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
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 160 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
232 233 234 235 236 237 238 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 232 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
200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 200 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
223 224 225 226 227 228 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 223 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, custom_args = {}) ⇒ Object
Capture both the target namespace URI and the matching prefix discovered during XML deserialization.
150 151 152 153 154 155 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 150 def target_namespace_from(model, value, custom_args = {}) model.target_namespace = value namespaces = custom_args[:namespaces] || {} model.target_namespace_prefix = namespaces.find { |_, namespace| namespace.uri == value }&.first end |
#valid? ⇒ Boolean
Quick validation check
216 217 218 219 |
# File 'lib/lutaml/xml/schema/xsd/schema.rb', line 216 def valid? # Basic validation: a parsed schema should declare a target namespace. !target_namespace.nil? && !target_namespace.empty? end |