Class: Rng::SchemaPreamble
- Inherits:
-
Object
- Object
- Rng::SchemaPreamble
- Defined in:
- lib/rng/schema_preamble.rb
Overview
Container for namespace and datatype declarations in RNC schema
Provides structured access to schema metadata that appears at the top of RNC files before the grammar content.
Instance Attribute Summary collapse
-
#datatypes ⇒ Object
readonly
Returns the value of attribute datatypes.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
Instance Method Summary collapse
-
#add_datatype(declaration) ⇒ Object
Add a datatype declaration.
-
#add_namespace(declaration) ⇒ Object
Add a namespace declaration.
-
#datatype_map ⇒ Hash<String, String>
Get a map of datatype prefixes to URIs.
-
#default_namespace ⇒ String?
Get the default namespace URI.
-
#empty? ⇒ Boolean
Check if preamble is empty.
-
#initialize ⇒ SchemaPreamble
constructor
Initialize an empty preamble.
-
#namespace_map ⇒ Hash<String, String>
Get a map of namespace prefixes to URIs.
Constructor Details
#initialize ⇒ SchemaPreamble
Initialize an empty preamble
22 23 24 25 |
# File 'lib/rng/schema_preamble.rb', line 22 def initialize @namespaces = [] @datatypes = [] end |
Instance Attribute Details
#datatypes ⇒ Object (readonly)
Returns the value of attribute datatypes.
19 20 21 |
# File 'lib/rng/schema_preamble.rb', line 19 def datatypes @datatypes end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
19 20 21 |
# File 'lib/rng/schema_preamble.rb', line 19 def namespaces @namespaces end |
Instance Method Details
#add_datatype(declaration) ⇒ Object
Add a datatype declaration
37 38 39 |
# File 'lib/rng/schema_preamble.rb', line 37 def add_datatype(declaration) @datatypes << declaration end |
#add_namespace(declaration) ⇒ Object
Add a namespace declaration
30 31 32 |
# File 'lib/rng/schema_preamble.rb', line 30 def add_namespace(declaration) @namespaces << declaration end |
#datatype_map ⇒ Hash<String, String>
Get a map of datatype prefixes to URIs
60 61 62 63 64 |
# File 'lib/rng/schema_preamble.rb', line 60 def datatype_map @datatypes.to_h do |dt| [dt.prefix, dt.uri] end end |
#default_namespace ⇒ String?
Get the default namespace URI
44 45 46 |
# File 'lib/rng/schema_preamble.rb', line 44 def default_namespace @namespaces.find(&:default?)&.uri end |
#empty? ⇒ Boolean
Check if preamble is empty
69 70 71 |
# File 'lib/rng/schema_preamble.rb', line 69 def empty? @namespaces.empty? && @datatypes.empty? end |
#namespace_map ⇒ Hash<String, String>
Get a map of namespace prefixes to URIs
51 52 53 54 55 |
# File 'lib/rng/schema_preamble.rb', line 51 def namespace_map @namespaces.select(&:prefixed?).to_h do |ns| [ns.prefix, ns.uri] end end |