Class: Lutaml::Rdf::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/rdf/namespace.rb

Class Method Summary collapse

Class Method Details

.==(other) ⇒ Object



43
44
45
46
# File 'lib/lutaml/rdf/namespace.rb', line 43

def ==(other)
  other.is_a?(Class) && other < Namespace &&
    other.uri == uri && other.prefix == prefix
end

.[](local_name) ⇒ Object



27
28
29
# File 'lib/lutaml/rdf/namespace.rb', line 27

def [](local_name)
  "#{uri}#{local_name}"
end

.hashObject



48
49
50
# File 'lib/lutaml/rdf/namespace.rb', line 48

def hash
  [uri, prefix].hash
end

.prefix(value = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/lutaml/rdf/namespace.rb', line 17

def prefix(value = nil)
  return @prefix if value.nil?
  if @prefix
    raise FrozenError,
          "#{name}.prefix is already set to #{@prefix.inspect}"
  end

  @prefix = value.to_s.freeze
end

.prefixed(local_name) ⇒ Object



31
32
33
# File 'lib/lutaml/rdf/namespace.rb', line 31

def prefixed(local_name)
  "#{prefix}:#{local_name}"
end

.resolve_compact_iri(compact_iri, namespaces) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/lutaml/rdf/namespace.rb', line 35

def resolve_compact_iri(compact_iri, namespaces)
  return compact_iri unless compact_iri.include?(":")

  pfx, local = compact_iri.split(":", 2)
  ns = namespaces.find { |n| n.prefix == pfx }
  ns ? ns[local] : compact_iri
end

.to_sObject



52
53
54
# File 'lib/lutaml/rdf/namespace.rb', line 52

def to_s
  "#{name}(prefix: #{prefix.inspect}, uri: #{uri.inspect})"
end

.uri(value = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/lutaml/rdf/namespace.rb', line 7

def uri(value = nil)
  return @uri if value.nil?
  if @uri
    raise FrozenError,
          "#{name}.uri is already set to #{@uri.inspect}"
  end

  @uri = value.freeze
end