Class: RDF::Normalize::RDFC10::IdentifierIssuer

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/normalize/rdfc10.rb

Instance Method Summary collapse

Constructor Details

#initialize(prefix = "c14n") ⇒ IdentifierIssuer

Returns a new instance of IdentifierIssuer.



396
397
398
# File 'lib/rdf/normalize/rdfc10.rb', line 396

def initialize(prefix = "c14n")
  @prefix, @counter, @issued = prefix, 0, {}
end

Instance Method Details

#dupIdentifierIssuer

Duplicate this issuer, ensuring that the issued identifiers remain distinct

Returns:



426
427
428
429
430
# File 'lib/rdf/normalize/rdfc10.rb', line 426

def dup
  other = super
  other.instance_variable_set(:@issued, @issued.dup)
  other
end

#identifier(node) ⇒ RDF::Node

Returns Canonical identifier assigned to node.

Returns:

  • (RDF::Node)

    Canonical identifier assigned to node



415
416
417
# File 'lib/rdf/normalize/rdfc10.rb', line 415

def identifier(node)
  @issued[node]
end

#inspectObject



432
433
434
# File 'lib/rdf/normalize/rdfc10.rb', line 432

def inspect
  "{#{@issued.map {|k,v| "#{k.id}: #{v}"}.join(', ')}}"
end

#issue_identifier(node) ⇒ String

Return an identifier for this BNode

Parameters:

  • node (RDF::Node)

Returns:

  • (String)

    Canonical identifier for node



403
404
405
406
407
408
# File 'lib/rdf/normalize/rdfc10.rb', line 403

def issue_identifier(node)
  @issued[node] ||= begin
    res, @counter = @prefix + @counter.to_s, @counter + 1
    res
  end
end

#issuedObject



410
411
412
# File 'lib/rdf/normalize/rdfc10.rb', line 410

def issued
  @issued.keys
end

#to_hashHash{Symbol => Symbol}

Returns the issued identifiers map.

Returns:

  • (Hash{Symbol => Symbol})

    the issued identifiers map



420
421
422
# File 'lib/rdf/normalize/rdfc10.rb', line 420

def to_hash
  @issued.inject({}) {|memo, (node, canon)| memo.merge(node.id => canon)}
end