Class: RDF::Literal::Token

Inherits:
RDF::Literal show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-1b20f426c35b/lib/rdf/model/literal/token.rb

Overview

A token literal.

Constant Summary

DATATYPE =

Since:

  • 0.2.3

RDF::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

#==, #compatible?, #comperable_datatype?, #eql?, #escape, #has_datatype?, #has_language?, #hash, #humanize, #inspect, #literal?, #method_missing, #object, #plain?, #respond_to_missing?, #simple?, #squish, #squish!, #valid?, #validate!, #value, #value_hash

Methods included from Term

#<=>, #==, #aggregate?, #compatible?, #eql?, #escape, #evaluate, #ndvars, #term?, #to_base, #to_term, #vars

Methods included from SPARQL::Algebra::Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #optimize, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

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)
  • language (Symbol)

    (nil) Language is downcased to ensure proper matching

  • lexical (String)

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

  • datatype (URI)

    (nil)

  • validate (Boolean)

    (false)

  • canonicalize (Boolean)

    (false)

Since:

  • 0.2.3



14
15
16
17
18
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-1b20f426c35b/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 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-1b20f426c35b/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:

Since:

  • 0.2.3



42
43
44
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-1b20f426c35b/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:

Since:

  • 0.2.3



34
35
36
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-1b20f426c35b/lib/rdf/model/literal/token.rb', line 34

def to_sym
  @object.to_sym
end