Class: RdfaParser::BNode
- Inherits:
-
Object
- Object
- RdfaParser::BNode
- Defined in:
- lib/rdfa_parser/bnode.rb
Overview
The BNode class creates RDF blank nodes.
Constant Summary collapse
- @@next_generated =
"a"
- @@named_nodes =
{}
Class Method Summary collapse
-
.reset(init = "a") ⇒ Object
Start identifier sequence from scratch.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
-
#hash ⇒ Object
Needed for uniq.
-
#identifier ⇒ Object
The identifier used used for this BNode.
-
#initialize(identifier = nil) ⇒ BNode
constructor
Create a new BNode, optionally accept a identifier for the BNode.
-
#to_n3 ⇒ String
Exports the BNode in N-Triples form.
-
#to_ntriples ⇒ String
Exports the BNode in N-Triples form.
- #to_s ⇒ Object
-
#xml_args ⇒ Object
Output URI as resource reference for RDF/XML.
Constructor Details
#initialize(identifier = nil) ⇒ BNode
Create a new BNode, optionally accept a identifier for the BNode. Otherwise, generated sequentially
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rdfa_parser/bnode.rb', line 8 def initialize(identifier = nil) if identifier != nil && self.valid_id?(identifier) # Generate a name if it's blank @identifier = (@@named_nodes[identifier] ||= identifier.to_s.length > 0 ? identifier : self ) else # Don't actually allocate the name until it's used, to save generation space # (and make checking test cases easier) @identifier = self end end |
Class Method Details
.reset(init = "a") ⇒ Object
Start identifier sequence from scratch
82 83 84 85 |
# File 'lib/rdfa_parser/bnode.rb', line 82 def self.reset(init = "a") @@next_generated = init @@named_nodes = {} end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
73 74 75 |
# File 'lib/rdfa_parser/bnode.rb', line 73 def eql?(other) other.is_a?(self.class) && self.identifier == other.identifier end |
#hash ⇒ Object
Needed for uniq
79 |
# File 'lib/rdfa_parser/bnode.rb', line 79 def hash; to_s.hash; end |
#identifier ⇒ Object
The identifier used used for this BNode. Not evaluated until this is called, which means that BNodes that are never used in a triple won’t polute the sequence.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rdfa_parser/bnode.rb', line 60 def identifier return @identifier unless @identifier.is_a?(BNode) if @identifier.equal?(self) # Generate from the sequence a..zzz, unless already taken @@next_generated = @@next_generated.succ while @@named_nodes.has_key?(@@next_generated) @identifier, @@next_generated = @@next_generated, @@next_generated.succ else # Previously allocated node @identifier = @identifier.identifier end @identifier end |
#to_n3 ⇒ String
34 35 36 |
# File 'lib/rdfa_parser/bnode.rb', line 34 def to_n3 "_:#{self.identifier}" end |
#to_ntriples ⇒ String
49 50 51 |
# File 'lib/rdfa_parser/bnode.rb', line 49 def to_ntriples self.to_n3 end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/rdfa_parser/bnode.rb', line 19 def to_s return self.identifier.to_s end |
#xml_args ⇒ Object
Output URI as resource reference for RDF/XML
54 55 56 |
# File 'lib/rdfa_parser/bnode.rb', line 54 def xml_args [{"rdf:nodeID" => self.identifier}] end |