Class: Reddy::BNode

Inherits:
Object
  • Object
show all
Defined in:
lib/reddy/bnode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier = nil) ⇒ BNode

Returns a new instance of BNode.



4
5
6
7
8
9
10
11
# File 'lib/reddy/bnode.rb', line 4

def initialize(identifier = nil)
  if identifier != nil && self.valid_id?(identifier) != false
    @identifier = identifier
  else
    @identifier = "bn" + self.hash.to_i.abs.to_s
	# perhaps this needs to be slightly cleverer - check whether it's negative, and if it is, append an extra bit on the end aaaaaas distinction. TODO
  end
end

Instance Attribute Details

#identifierObject

Returns the value of attribute identifier.



3
4
5
# File 'lib/reddy/bnode.rb', line 3

def identifier
  @identifier
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


13
14
15
# File 'lib/reddy/bnode.rb', line 13

def eql? (other)
  other.is_a?(self.class) && other.identifier == self.identifier
end

#to_n3String

Exports the BNode in N-Triples form.

Example

b = BNode.new; b.to_n3  # => returns a string of the BNode in n3 form

Returns

Returns:

  • (String)

    The BNode in n3.

Author:

  • Tom Morris



30
31
32
# File 'lib/reddy/bnode.rb', line 30

def to_n3
  "_:" + @identifier
end

#to_ntriplesString

Exports the BNode in N-Triples form.

Example

b = BNode.new; b.to_ntriples  # => returns a string of the BNode in N-Triples form

Returns

Returns:

  • (String)

    The BNode in N-Triples.

Author:

  • Tom Morris



46
47
48
# File 'lib/reddy/bnode.rb', line 46

def to_ntriples
  self.to_n3
end

#to_sString

Returns the identifier as a string.

Returns

Returns:

  • (String)

    Blank node identifier.

Author:

  • Tom Morris



57
58
59
# File 'lib/reddy/bnode.rb', line 57

def to_s
  @identifier
end