Class: RDF::Literal::Token

Inherits:
RDF::Literal show all
Defined in:
lib/rdf/model/literal/token.rb

Overview

A token literal.

Constant Summary collapse

DATATYPE =

Since:

  • 0.2.3

XSD.token
GRAMMAR =

FIXME

Since:

  • 0.2.3

/\A[^\x0D\x0A\x09]+\z/i.freeze

Constants inherited from RDF::Literal

FALSE, TRUE, ZERO

Instance Attribute Summary

Attributes inherited from RDF::Literal

#datatype, #language

Instance Method Summary collapse

Methods inherited from RDF::Literal

#==, #anonymous?, #canonicalize, #comperable_datatype?, datatyped_class, #eql?, #has_datatype?, #has_language?, #hash, #inspect, #invalid?, #literal?, new, #object, #plain?, #valid?, #validate!, #value

Methods included from Term

#<=>, #==, #constant?, #eql?, #variable?

Methods included from Value

#graph?, #inspect, #inspect!, #iri?, #literal?, #node?, #resource?, #statement?, #to_ntriples, #to_quad, #to_rdf, #type_error, #uri?, #variable?

Constructor Details

#initialize(value, options = {}) ⇒ Token

Returns a new instance of Token.

Parameters:

  • value (Symbol, #to_s)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :lexical (String) — default: nil

Since:

  • 0.2.3



14
15
16
17
18
19
# File 'lib/rdf/model/literal/token.rb', line 14

def initialize(value, options = {})
  @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
  @string   = options[:lexical] if options.has_key?(:lexical)
  @string   ||= value if value.is_a?(String)
  @object   = value.is_a?(Symbol) ? value : value.to_s
end

Instance Method Details

#canonicalize!RDF::Literal

Converts this literal into its canonical lexical representation.

Returns:

See Also:

Since:

  • 0.2.3



26
27
28
29
# File 'lib/rdf/model/literal/token.rb', line 26

def canonicalize!
  @string = @object.to_s if @object
  self
end

#to_sString

Returns the value as a string.

Returns:

  • (String)

Since:

  • 0.2.3



43
44
45
# File 'lib/rdf/model/literal/token.rb', line 43

def to_s
  @string || @object.to_s
end

#to_symSymbol

Returns the value as a symbol.

Returns:

  • (Symbol)

Since:

  • 0.2.3



35
36
37
# File 'lib/rdf/model/literal/token.rb', line 35

def to_sym
  @object.to_sym
end