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

RDF::URI("http://www.w3.org/2001/XMLSchema#token")
GRAMMAR =

FIXME

Since:

  • 0.2.3

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

Constants inherited from RDF::Literal

FALSE, TRUE, XSD_STRING, ZERO

Instance Attribute Summary

Attributes inherited from RDF::Literal

#datatype, #direction, #language

Instance Method Summary collapse

Methods inherited from RDF::Literal

#<=>, #==, #compatible?, #comperable_datatype2?, #comperable_datatype?, #datatype?, #direction?, #eql?, #escape, #hash, #humanize, #inspect, #language?, #literal?, #method_missing, #object, #plain?, #respond_to_missing?, #simple?, #squish, #squish!, #valid?, #validate!, #value, #value_hash

Methods included from Term

#<=>, #==, #compatible?, #eql?, #escape, #term?, #terms, #to_base, #to_term

Methods included from Value

#anonymous?, #canonicalize, #constant?, #graph?, #inspect, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #start_with?, #statement?, #term?, #to_nquads, #to_ntriples, #to_rdf, #to_term, #type_error, #uri?, #valid?, #validate!, #variable?

Constructor Details

#initialize(value, datatype: nil, lexical: nil, **options) ⇒ Token

Returns a new instance of Token.

Parameters:

  • value (String, Symbol, #to_sym)
  • value (Object)
  • direction (Symbol)

    (nil) Initial text direction.

  • language (Symbol)

    (nil) Language is downcased to ensure proper matching

  • lexical (String) (defaults to: nil)

    (nil) Supplied lexical representation of this literal, otherwise it comes from transforming value to a string form..

  • datatype (URI) (defaults to: nil)

    (nil)

  • validate (Boolean)

    (false)

  • canonicalize (Boolean)

    (false)

Since:

  • 0.2.3



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

def initialize(value, datatype: nil, lexical: nil, **options)
  @datatype = RDF::URI(datatype || self.class.const_get(:DATATYPE))
  @string   = lexical || (value if value.is_a?(String))
  @object   = value.is_a?(Symbol) ? value : value.to_sym
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Literal

Instance Method Details

#canonicalize!RDF::Literal

Converts this literal into its canonical lexical representation.

Returns:

See Also:

Since:

  • 0.2.3



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

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

#to_sString

Returns the value as a string.

Returns:

  • (String)

Since:

  • 0.2.3



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

def to_s
  @string || @object.to_s
end

#to_symSymbol

Returns the value as a symbol.

Returns:

  • (Symbol)

Since:

  • 0.2.3



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

def to_sym
  @object.to_sym
end