Sha256: ff0cf817417d4b4ad20900c9d6cc9c71db4f84da71024d9ffb2bcccdf8d4c42c

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

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

    ##
    # @param  [Symbol, #to_s]  value
    # @option options [String] :lexical (nil)
    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

    ##
    # Converts the literal into its canonical lexical representation.
    #
    # @return [Literal]
    # @see    http://www.w3.org/TR/xmlschema-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 # class Token
end; end # class RDF::Literal

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rdf-0.2.3 lib/rdf/model/literal/token.rb