Class: Uniword::Ooxml::Schema::OoxmlSchema
- Inherits:
-
Object
- Object
- Uniword::Ooxml::Schema::OoxmlSchema
- Defined in:
- lib/uniword/ooxml/schema/ooxml_schema.rb
Overview
OOXML Schema loaded from external YAML configuration.
Responsibility: Load and provide access to OOXML element definitions. Single Responsibility - schema management only.
Follows “Configuration over Convention” - schema is defined in external YAML files following ISO/IEC 29500 specification.
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.aggregate_schema_files(loader_config, loader_file) ⇒ Hash
Aggregate multiple schema files into single schema.
-
.default_loader_path ⇒ String
Get default loader path.
-
.load(schema_file = nil) ⇒ OoxmlSchema
Load schema from YAML file or multi-file loader.
-
.load_from_loader(loader_file) ⇒ OoxmlSchema
Load schema from multi-file loader configuration.
-
.loader_config?(file_path) ⇒ Boolean
Check if file is a loader configuration.
Instance Method Summary collapse
-
#definition_for(element_class_or_name) ⇒ ElementDefinition
Get element definition by element class or name.
-
#element(name) ⇒ ElementDefinition
Get element definition by name (alias for definition_for).
-
#element_count ⇒ Integer
Get count of defined elements.
-
#element_names ⇒ Array<Symbol>
Get all element names.
-
#has_element?(element_class_or_name) ⇒ Boolean
Check if schema has definition for element.
-
#initialize(config) ⇒ OoxmlSchema
constructor
Initialize schema from configuration hash.
Constructor Details
#initialize(config) ⇒ OoxmlSchema
Initialize schema from configuration hash
61 62 63 64 65 66 67 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 61 def initialize(config) validate_schema_config(config) @version = config.dig(:schema, :version) @namespace = config.dig(:schema, :namespace) @elements = build_element_definitions(config[:elements] || {}) end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
22 23 24 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 22 def elements @elements end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
22 23 24 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 22 def namespace @namespace end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
22 23 24 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 22 def version @version end |
Class Method Details
.aggregate_schema_files(loader_config, loader_file) ⇒ Hash
Aggregate multiple schema files into single schema
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 191 def self.aggregate_schema_files(loader_config, loader_file) base_path = File.dirname(loader_file) all_elements = {} # Load each schema file and merge elements loader_config[:schema_files].each do |schema_file| file_path = File.join(base_path, schema_file) next unless File.exist?(file_path) file_config = Configuration::ConfigurationLoader.load_file(file_path) # Merge elements from this file all_elements.merge!(file_config[:elements]) if file_config[:elements] end # Build combined schema configuration { schema: { version: loader_config[:version], namespace: loader_config[:namespaces]&.dig(:w), }, elements: all_elements, } end |
.default_loader_path ⇒ String
Get default loader path
220 221 222 223 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 220 def self.default_loader_path File.("../../../../config/ooxml/schema_loader.yml", __dir__) end |
.load(schema_file = nil) ⇒ OoxmlSchema
Load schema from YAML file or multi-file loader
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 35 def self.load(schema_file = nil) schema_file ||= default_loader_path # Check if this is a loader configuration or direct schema file if loader_config?(schema_file) load_from_loader(schema_file) else # Legacy single-file loading config = Configuration::ConfigurationLoader.load_file(schema_file) new(config) end end |
.load_from_loader(loader_file) ⇒ OoxmlSchema
Load schema from multi-file loader configuration
52 53 54 55 56 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 52 def self.load_from_loader(loader_file) loader_config = Configuration::ConfigurationLoader.load_file(loader_file) combined_schema = aggregate_schema_files(loader_config, loader_file) new(combined_schema) end |
.loader_config?(file_path) ⇒ Boolean
Check if file is a loader configuration
182 183 184 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 182 def self.loader_config?(file_path) file_path.end_with?("schema_loader.yml") end |
Instance Method Details
#definition_for(element_class_or_name) ⇒ ElementDefinition
Get element definition by element class or name
80 81 82 83 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 80 def definition_for(element_class_or_name) name = normalize_name(element_class_or_name) @elements[name] || raise_element_not_found(name) end |
#element(name) ⇒ ElementDefinition
Get element definition by name (alias for definition_for)
89 90 91 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 89 def element(name) @elements[name.to_sym] end |
#element_count ⇒ Integer
Get count of defined elements
112 113 114 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 112 def element_count @elements.count end |
#element_names ⇒ Array<Symbol>
Get all element names
105 106 107 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 105 def element_names @elements.keys end |
#has_element?(element_class_or_name) ⇒ Boolean
Check if schema has definition for element
97 98 99 100 |
# File 'lib/uniword/ooxml/schema/ooxml_schema.rb', line 97 def has_element?(element_class_or_name) name = normalize_name(element_class_or_name) @elements.key?(name) end |