Sha256: e9d8532aaf5a136c4c4356ccfd325b545e90aa264ac657dd62a896bed5bb07fa

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 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  [Symbol, #to_s]  value
    # @option options [String] :lexical (nil)
    def initialize(value, options = {})
      @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
      @string   = options[:lexical] if options.has_key?(:lexical)
      @string   ||= value if value.is_a?(String)
      @object   = value.is_a?(Symbol) ? value : value.to_s
    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

10 entries across 10 versions & 1 rubygems

Version Path
rdf-2.1.1 lib/rdf/model/literal/token.rb
rdf-2.1.0 lib/rdf/model/literal/token.rb
rdf-2.0.2 lib/rdf/model/literal/token.rb
rdf-2.0.1 lib/rdf/model/literal/token.rb
rdf-2.0.0 lib/rdf/model/literal/token.rb
rdf-2.0.0.beta2 lib/rdf/model/literal/token.rb
rdf-2.0.0.beta1 lib/rdf/model/literal/token.rb
rdf-1.99.1 lib/rdf/model/literal/token.rb
rdf-1.99.0.1 lib/rdf/model/literal/token.rb
rdf-1.99.0 lib/rdf/model/literal/token.rb