Class: Lutaml::Rdf::NamespaceSet
- Inherits:
-
Object
- Object
- Lutaml::Rdf::NamespaceSet
- Includes:
- Enumerable
- Defined in:
- lib/lutaml/rdf/namespace_set.rb
Instance Method Summary collapse
- #[](prefix) ⇒ Object
- #add(namespace_class) ⇒ Object
- #compact(full_uri) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(*namespace_classes) ⇒ NamespaceSet
constructor
A new instance of NamespaceSet.
- #merge(other_set) ⇒ Object
- #resolve_compact_iri(compact_iri) ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(*namespace_classes) ⇒ NamespaceSet
Returns a new instance of NamespaceSet.
8 9 10 11 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 8 def initialize(*namespace_classes) @by_prefix = {} namespace_classes.each { |ns| add(ns) } end |
Instance Method Details
#[](prefix) ⇒ Object
23 24 25 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 23 def [](prefix) @by_prefix[prefix] end |
#add(namespace_class) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 13 def add(namespace_class) pfx = namespace_class.prefix if @by_prefix.key?(pfx) && @by_prefix[pfx] != namespace_class raise ArgumentError, "Prefix '#{pfx}' conflicts: #{@by_prefix[pfx].name} vs #{namespace_class.name}" end @by_prefix[pfx] = namespace_class self end |
#compact(full_uri) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 31 def compact(full_uri) each do |ns| next unless full_uri.start_with?(ns.uri) local = full_uri.delete_prefix(ns.uri) return ns.prefixed(local) end nil end |
#each ⇒ Object
41 42 43 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 41 def each(&) @by_prefix.each_value(&) end |
#empty? ⇒ Boolean
49 50 51 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 49 def empty? @by_prefix.empty? end |
#merge(other_set) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 61 def merge(other_set) return self if equal?(other_set) other_set.each { |ns| add(ns) } self end |
#resolve_compact_iri(compact_iri) ⇒ Object
27 28 29 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 27 def resolve_compact_iri(compact_iri) Namespace.resolve_compact_iri(compact_iri, to_a) end |
#size ⇒ Object
45 46 47 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 45 def size @by_prefix.size end |
#to_a ⇒ Object
53 54 55 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 53 def to_a @by_prefix.values end |
#to_hash ⇒ Object
57 58 59 |
# File 'lib/lutaml/rdf/namespace_set.rb', line 57 def to_hash @by_prefix.transform_values(&:uri) end |