Class: Redland::Literal

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

Overview

overriding literal to give nice access to datatype and to access the stored value as correct ruby type

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(value, type) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/owl.rb', line 13

def self.create(value, type)
  raise "literal datatype may not be nil" unless type
  type = parse_datatype_uri(value) if OpenTox::Owl::PARSE_LITERAL_TYPE==type
  
  if type.is_a?(Redland::Uri)
    Redland::Literal.new(value.to_s,nil,type)
  else
    Redland::Literal.new(value.to_s,nil,Redland::Uri.new(type.to_s))
  end
end

Instance Method Details

#datatypeObject

the literal node of the ruby swig api provdides the ‘value’ of a literal but not the ‘datatype’ found solution in mailing list



26
27
28
29
# File 'lib/owl.rb', line 26

def datatype
  uri = Redland.librdf_node_get_literal_value_datatype_uri(self.node)
  return Redland.librdf_uri_to_string(uri) if uri
end

#get_valueObject

gets value of literal, value class is se according to literal datatype



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

def get_value
  Redland::Literal.parse_value( self.value, self.datatype )
end