Class: RDF::TypedLiteralNode

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

Overview

A typed literal node.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lexical_form, datatype_uri) ⇒ TypedLiteralNode

Creates a new TypedLiteralNode using the specified lexical_form and datatype_uri. Raises an ArgumentError if datatype_uri is empty. If datatype_uri is a UriNode, it will automatically convert it to just the URI string.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
# File 'lib/rdf/typed_literal_node.rb', line 12

def initialize(lexical_form, datatype_uri)
  @lexical_form = lexical_form.to_s
  @datatype_uri = RDF::UriNode?(datatype_uri) ? datatype_uri.uri : datatype_uri.to_s
  
  raise ArgumentError, "datatype_uri cannot be empty" if @datatype_uri.empty?
end

Instance Attribute Details

#datatype_uriObject (readonly)

the datatype uri of this TypedLiteralNode.



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

def datatype_uri
  @datatype_uri
end

#lexical_formObject (readonly)

the lexical form of this TypedLiteralNode.



5
6
7
# File 'lib/rdf/typed_literal_node.rb', line 5

def lexical_form
  @lexical_form
end

Instance Method Details

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

Returns true if o is a TypedLiteralNode with the same lexical_form and datatype_uri.



20
21
22
23
24
25
# File 'lib/rdf/typed_literal_node.rb', line 20

def ==(o)
  if RDF::TypedLiteralNode?(o)
    lexical_form == o.lexical_form &&
    datatype_uri == o.datatype_uri
  end
end

#hashObject

Returns a hash value for this TypedLiteralNode.



30
31
32
# File 'lib/rdf/typed_literal_node.rb', line 30

def hash
  [375836169, lexical_form.hash, datatype_uri.hash].hash
end

#to_sObject

Returns the NTriples representation of this TypedLiteralNode.



35
36
37
# File 'lib/rdf/typed_literal_node.rb', line 35

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