Class: RDF::Literal::Token
- Inherits:
-
RDF::Literal
- Object
- RDF::Literal
- RDF::Literal::Token
- Defined in:
- lib/rdf/model/literal/token.rb
Overview
A token literal.
Constant Summary collapse
- DATATYPE =
RDF::URI("http://www.w3.org/2001/XMLSchema#token")
- GRAMMAR =
FIXME
/\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
-
#canonicalize! ⇒ RDF::Literal
Converts this literal into its canonical lexical representation.
-
#initialize(value, datatype: nil, lexical: nil, **options) ⇒ Token
constructor
A new instance of Token.
-
#to_s ⇒ String
Returns the value as a string.
-
#to_sym ⇒ Symbol
Returns the value as a symbol.
Methods inherited from RDF::Literal
#<=>, #==, #compatible?, #comperable_datatype2?, #comperable_datatype?, #datatype?, datatype_map, datatyped_class, #direction?, #english?, #eql?, #escape, #freeze, #hash, #humanize, #inspect, #language?, #literal?, new, #object, #plain?, #simple?, #squish, #squish!, #valid?, #validate!, #value, #value_hash
Methods included from Term
#<=>, #==, #compatible?, #eql?, #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.
14 15 16 17 18 |
# File 'lib/rdf/model/literal/token.rb', line 14 def initialize(value, datatype: nil, lexical: nil, **) @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.
25 26 27 28 |
# File 'lib/rdf/model/literal/token.rb', line 25 def canonicalize! @string = @object.to_s if @object self end |
#to_s ⇒ String
Returns the value as a string.
42 43 44 |
# File 'lib/rdf/model/literal/token.rb', line 42 def to_s @string || @object.to_s end |
#to_sym ⇒ Symbol
Returns the value as a symbol.
34 35 36 |
# File 'lib/rdf/model/literal/token.rb', line 34 def to_sym @object.to_sym end |