Sha256: 46b9d7cee5919f7eec2c1989680214187b70d92da03c712e0068c5ab16b74fda
Contents?: true
Size: 1.3 KB
Versions: 11
Compression:
Stored size: 1.3 KB
Contents
require 'active_rdf' # Represents an RDF literal, optionally datatyped. # TODO: language tags class Literal Namespace.register :xsd, 'http://www.w3.org/2001/XMLSchema#' attr_reader :value, :type, :language @value, @type, @language = nil, nil, nil # Constructs literal with given datatype. If no datatype is given, automatic # conversion from Ruby to XSD datatype is tried. def initialize(value, type_or_language=nil) @value = value if type_or_language.nil? # deduce type from the given value @type = case value when String XSD::string when Date, Time, DateTime XSD::date when TrueClass, FalseClass XSD::boolean when Fixnum XSD::integer end elsif type_or_language[0..0] == "@" # a language tag has been given @language = type_or_language[1..type_or_language.length] else # the type_or_language was not empty and did not start with a @ so it must be a data type @type = type_or_language end end # returns string serialisation of literal, e.g. "test"^^xsd:string def to_s if type "\"#{value}\"^^#{type.to_s}" elsif language "\"#{value}\"@#{language}" else "\"value\"" end end end
Version data entries
11 entries across 11 versions & 1 rubygems