Class: RDF::BlankNode

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

Overview

A blank node. In RDF a blank node is a graph local node, it can be used only with the graph to which it is associated. See UnassociatedBlankNodeSubjectError and UnassociatedBlankNodeObjectError.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, graph = nil) ⇒ BlankNode

Creates a new blank node using the specified name and graph. Raises an ArgumentError if name is an empty string, or if graph is nil.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
# File 'lib/rdf/blank_node.rb', line 13

def initialize(name, graph = nil)
  @name = name.to_s
  @graph = graph
  
  raise ArgumentError, 'name cannot be empty' if @name.empty?
  raise ArgumentError, 'graph cannot be nil' if @graph.nil?
end

Instance Attribute Details

#graphObject (readonly)

the graph to which this BlankNode is associated.



7
8
9
# File 'lib/rdf/blank_node.rb', line 7

def graph
  @graph
end

#nameObject (readonly)

the name of this BlankNode.



9
10
11
# File 'lib/rdf/blank_node.rb', line 9

def name
  @name
end

Instance Method Details

#==(o) ⇒ Object Also known as: eql?

Returns true if o is a BlankNode with the same graph and name.



22
23
24
25
26
27
# File 'lib/rdf/blank_node.rb', line 22

def ==(o)
  if RDF::BlankNode?(o)
    graph == o.graph &&
    name == o.name
  end
end

#hashObject

Returns a hash value for this BlankNode.



32
33
34
# File 'lib/rdf/blank_node.rb', line 32

def hash
  [769847830, graph.hash, name.hash].hash
end

#to_sObject

Returns the NTriples representation of this BlankNode.



37
38
39
# File 'lib/rdf/blank_node.rb', line 37

def to_s
  Format::NTriples.export_node(self)
end