Sha256: 5f6d9bd660faf10e546813c03205ededbefb05b1f2abf47c6d4fcfcae2177d9c

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

# coding: utf-8
require 'base64'

module RDF; class Literal
  ##
  # More specific sub-types of double
  # Derived types
  # @see http://www.w3.org/TR/xpath-functions/#datatypes
  
  ##
  # anyURI represents a Uniform Resource Identifier Reference (URI).
  # An anyURI value can be absolute or relative, and may have an
  # optional fragment identifier (i.e., it may be a URI Reference).
  # This type should be used to specify the intention that the value fulfills
  # the role of a URI as defined by [RFC 2396], as amended by [RFC 2732].
  #
  # @see http://www.w3.org/TR/xmlschema11-2/#anyURI
  # @see http://www.ietf.org/rfc/rfc2396.txt
  # @see http://www.ietf.org/rfc/rfc2732.txt
  class AnyURI < RDF::Literal
    DATATYPE = XSD.anyURI

    ##
    # @param  [String, Object] value
    #   If given a string, it will decode it as an object value.
    #   Otherwise, it will take the value as the object and encode to retrieve a value
    # @param [String] lexical (nil)
    def initialize(value, datatype: nil, lexical: nil, **options)
      super(value, datatype: datatype, lexical: lexical)
      @object = RDF::URI(value)
      canonicalize! unless value.is_a?(String)
    end

    ##
    # Converts this literal into its canonical lexical representation.
    #
    # @return [RDF::Literal] `self`
    def canonicalize!
      @string = @object.canonicalize
      self
    end

    ##
    # Returns `true` if the value adheres to the defined grammar of the
    # datatype.
    #
    # @return [Boolean]
    def valid?
      @object.validate! rescue false
    end
  end
end; end #RDF::Literal

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rdf-xsd-3.0.0 lib/rdf/xsd/any_uri.rb
rdf-xsd-2.2.1 lib/rdf/xsd/any_uri.rb
rdf-xsd-2.2.0 lib/rdf/xsd/any_uri.rb
rdf-xsd-2.1.0 lib/rdf/xsd/any_uri.rb