Sha256: bdec850a5fabe8379e3941d099ca6edf19e5ac77b9d77e1a77ead4df3e1ab261

Contents?: true

Size: 1.11 KB

Versions: 16

Compression:

Stored size: 1.11 KB

Contents

module RDF; class Literal
  ##
  # A token literal.
  #
  # @see   http://www.w3.org/TR/xmlschema11-2/#token
  # @since 0.2.3
  class Token < Literal
    DATATYPE = RDF::XSD.token
    GRAMMAR  = /\A[^\x0D\x0A\x09]+\z/i.freeze # FIXME

    ##
    # @param  [String, Symbol, #to_sym]  value
    # @param  (see Literal#initialize)
    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

    ##
    # Converts this literal into its canonical lexical representation.
    #
    # @return [RDF::Literal] `self`
    # @see    http://www.w3.org/TR/xmlschema11-2/#boolean
    def canonicalize!
      @string = @object.to_s if @object
      self
    end

    ##
    # Returns the value as a symbol.
    #
    # @return [Symbol]
    def to_sym
      @object.to_sym
    end

    ##
    # Returns the value as a string.
    #
    # @return [String]
    def to_s
      @string || @object.to_s
    end
  end # Token
end; end # RDF::Literal

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rdf-3.0.2 lib/rdf/model/literal/token.rb
rdf-3.0.1 lib/rdf/model/literal/token.rb
rdf-3.0.0 lib/rdf/model/literal/token.rb
rdf-2.2.12 lib/rdf/model/literal/token.rb
rdf-2.2.11 lib/rdf/model/literal/token.rb
rdf-2.2.10 lib/rdf/model/literal/token.rb
rdf-2.2.9 lib/rdf/model/literal/token.rb
rdf-2.2.8 lib/rdf/model/literal/token.rb
rdf-2.2.7 lib/rdf/model/literal/token.rb
rdf-2.2.6 lib/rdf/model/literal/token.rb
rdf-2.2.5 lib/rdf/model/literal/token.rb
rdf-2.2.4 lib/rdf/model/literal/token.rb
rdf-2.2.3 lib/rdf/model/literal/token.rb
rdf-2.2.1 lib/rdf/model/literal/token.rb
rdf-2.2.0 lib/rdf/model/literal/token.rb
rdf-2.2.0.pre.rc1 lib/rdf/model/literal/token.rb