Class: RDF::Literal::Token

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

Overview

A token literal.

See Also:

Since:

Constant Summary

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 Method Summary (collapse)

Methods inherited from RDF::Literal

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

Methods included from Term

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

Methods included from Value

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

Constructor Details

- (Token) initialize(value, options = {})

A new instance of Token

Parameters:

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

    a customizable set of options

Options Hash (options):

  • (String) :lexical — 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] || DATATYPE)
  @string   = options[:lexical] if options.has_key?(:lexical)
  @string   = value if !defined?(@string) && value.is_a?(String)
  @object   = value.is_a?(Symbol) ? value : value.to_s
end

Instance Method Details

- (RDF::Literal) canonicalize!

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

- (String) to_s

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

- (Symbol) to_sym

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