Class: RDF::URI

Inherits:
Object show all
Includes:
Resource
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-reasoner-0705d0a3eca4/lib/rdf/reasoner/extensions.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-spec-266178176aa3/lib/rdf/spec/inspects.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/json-ld-5d3887dcf198/lib/json/ld/extensions.rb

Overview

A Uniform Resource Identifier (URI). Also compatible with International Resource Identifier (IRI)

http://en.wikipedia.org/wiki/Internationalized_Resource_Identifier

Examples:

Creating a URI reference (1)

uri = RDF::URI.new("http://rubygems.org/gems/rdf")

Creating a URI reference (2)

uri = RDF::URI.new(scheme: 'http', host: 'rubygems.org', path: '/gems/rdf')
  #=> RDF::URI.new("http://rubygems.org/gems/rdf")

Creating an interned URI reference

uri = RDF::URI.intern("http://rubygems.org/gems/rdf")

Getting the string representation of a URI

uri.to_s #=> "http://rubygems.org/gems/rdf"

See Also:

Constant Summary collapse

CACHE_SIZE =

Defines the maximum number of interned URI references that can be held cached in memory at any one time.

-1 # unlimited by default
UCSCHAR =

IRI components

Regexp.compile(<<-EOS.gsub(/\s+/, ''))
  [\\u00A0-\\uD7FF]|[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFEF]|
  [\\u{10000}-\\u{1FFFD}]|[\\u{20000}-\\u{2FFFD}]|[\\u{30000}-\\u{3FFFD}]|
  [\\u{40000}-\\u{4FFFD}]|[\\u{50000}-\\u{5FFFD}]|[\\u{60000}-\\u{6FFFD}]|
  [\\u{70000}-\\u{7FFFD}]|[\\u{80000}-\\u{8FFFD}]|[\\u{90000}-\\u{9FFFD}]|
  [\\u{A0000}-\\u{AFFFD}]|[\\u{B0000}-\\u{BFFFD}]|[\\u{C0000}-\\u{CFFFD}]|
  [\\u{D0000}-\\u{DFFFD}]|[\\u{E1000}-\\u{EFFFD}]
EOS
IPRIVATE =
Regexp.compile("[\\uE000-\\uF8FF]|[\\u{F0000}-\\u{FFFFD}]|[\\u100000-\\u10FFFD]").freeze
SCHEME =
Regexp.compile("[A-Za-z](?:[A-Za-z0-9+-\.])*").freeze
PORT =
Regexp.compile("[0-9]*").freeze
IP_literal =

Simplified, no IPvFuture

Regexp.compile("\\[[0-9A-Fa-f:\\.]*\\]").freeze
PCT_ENCODED =
Regexp.compile("%[0-9A-Fa-f][0-9A-Fa-f]").freeze
GEN_DELIMS =
Regexp.compile("[:/\\?\\#\\[\\]@]").freeze
SUB_DELIMS =
Regexp.compile("[!\\$&'\\(\\)\\*\\+,;=]").freeze
RESERVED =
Regexp.compile("(?:#{GEN_DELIMS}|#{SUB_DELIMS})").freeze
UNRESERVED =
Regexp.compile("[A-Za-z0-9\._~-]").freeze
IUNRESERVED =
Regexp.compile("[A-Za-z0-9\._~-]|#{UCSCHAR}").freeze
IPCHAR =
Regexp.compile("(?:#{IUNRESERVED}|#{PCT_ENCODED}|#{SUB_DELIMS}|:|@)").freeze
IQUERY =
Regexp.compile("(?:#{IPCHAR}|#{IPRIVATE}|/|\\?)*").freeze
IFRAGMENT =
Regexp.compile("(?:#{IPCHAR}|/|\\?)*").freeze.freeze
ISEGMENT =
Regexp.compile("(?:#{IPCHAR})*").freeze
ISEGMENT_NZ =
Regexp.compile("(?:#{IPCHAR})+").freeze
ISEGMENT_NZ_NC =
Regexp.compile("(?:(?:#{IUNRESERVED})|(?:#{PCT_ENCODED})|(?:#{SUB_DELIMS})|@)+").freeze
IPATH_ABEMPTY =
Regexp.compile("(?:/#{ISEGMENT})*").freeze
IPATH_ABSOLUTE =
Regexp.compile("/(?:(?:#{ISEGMENT_NZ})(/#{ISEGMENT})*)?").freeze
IPATH_NOSCHEME =
Regexp.compile("(?:#{ISEGMENT_NZ_NC})(?:/#{ISEGMENT})*").freeze
IPATH_ROOTLESS =
Regexp.compile("(?:#{ISEGMENT_NZ})(?:/#{ISEGMENT})*").freeze
IPATH_EMPTY =
Regexp.compile("").freeze
IREG_NAME =
Regexp.compile("(?:(?:#{IUNRESERVED})|(?:#{PCT_ENCODED})|(?:#{SUB_DELIMS}))*").freeze
IHOST =
Regexp.compile("(?:#{IP_literal})|(?:#{IREG_NAME})").freeze
IUSERINFO =
Regexp.compile("(?:(?:#{IUNRESERVED})|(?:#{PCT_ENCODED})|(?:#{SUB_DELIMS})|:)*").freeze
IAUTHORITY =
Regexp.compile("(?:#{IUSERINFO}@)?#{IHOST}(?::#{PORT})?").freeze
IRELATIVE_PART =
Regexp.compile("(?:(?://#{IAUTHORITY}(?:#{IPATH_ABEMPTY}))|(?:#{IPATH_ABSOLUTE})|(?:#{IPATH_NOSCHEME})|(?:#{IPATH_EMPTY}))").freeze
IRELATIVE_REF =
Regexp.compile("^#{IRELATIVE_PART}(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$").freeze
IHIER_PART =
Regexp.compile("(?:(?://#{IAUTHORITY}#{IPATH_ABEMPTY})|(?:#{IPATH_ABSOLUTE})|(?:#{IPATH_ROOTLESS})|(?:#{IPATH_EMPTY}))").freeze
IRI =
Regexp.compile("^#{SCHEME}:(?:#{IHIER_PART})(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$").freeze
IRI_PARTS =

Split an IRI into it's component parts

/^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/.freeze
RDS_2A =

Remove dot expressions regular expressions

/^\.?\.\/(.*)$/.freeze
RDS_2B1 =
/^\/\.$/.freeze
RDS_2B2 =
/^(?:\/\.\/)(.*)$/.freeze
RDS_2C1 =
/^\/\.\.$/.freeze
RDS_2C2 =
/^(?:\/\.\.\/)(.*)$/.freeze
RDS_2D =
/^\.\.?$/.freeze
RDS_2E =
/^(\/?[^\/]*)(\/?.*)?$/.freeze
PORT_MAPPING =

Remove port, if it is standard for the scheme when normalizing

{
  "http"     => 80,
  "https"    => 443,
  "ftp"      => 21,
  "tftp"     => 69,
  "sftp"     => 22,
  "ssh"      => 22,
  "svn+ssh"  => 22,
  "telnet"   => 23,
  "nntp"     => 119,
  "gopher"   => 70,
  "wais"     => 210,
  "ldap"     => 389,
  "prospero" => 1525
}
NON_HIER_SCHEMES =

List of schemes known not to be hierarchical

%w(
  about acct bitcoin callto cid data fax geo gtalk h323 iax icon im jabber
  jms magnet mailto maps news pres proxy session sip sips skype sms spotify stun stuns
  tag tel turn turns tv urn javascript
).freeze
HOST_FROM_AUTHORITY_RE =
/(?:[^@]+@)?([^:]+)(?::.*)?$/.freeze
PORT_FROM_AUTHORITY_RE =
/:(\d+)$/.freeze
@@entailments =
{}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

new, #resource?

Methods included from Term

#<=>, #aggregate?, #compatible?, #escape, #evaluate, #ndvars, #term?, #to_base, #to_term, #vars

Methods included from SPARQL::Algebra::Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #optimize, register_extension, #to_sxp_bin, #variable?

Methods included from Value

#anonymous?, #constant?, #graph?, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #start_with?, #statement?, #term?, #to_nquads, #to_ntriples, #to_rdf, #to_term, #type_error, #variable?

Constructor Details

#initialize(uri, **options) ⇒ URI #initialize(**options) ⇒ URI

Returns a new instance of URI

Overloads:

  • #initialize(uri, **options) ⇒ URI

    Parameters:

  • #initialize(**options) ⇒ URI

    Parameters:

    • options (Hash{Symbol => Object})
    • validate (Boolean)

      (false)

    • canonicalize (Boolean)

      (false)



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 224

def initialize(*args, validate: false, canonicalize: false, **options)
  @value = @object = @hash = nil
  uri = args.first
  if uri
    @value = uri.to_s
    if @value.encoding != Encoding::UTF_8
      @value = @value.dup if @value.frozen?
      @value.force_encoding(Encoding::UTF_8)
      @value.freeze
    end
  else
    %w(
      scheme
      user password userinfo
      host port authority
      path query fragment
    ).map(&:to_sym).each do |meth|
      if options.has_key?(meth)
        self.send("#{meth}=".to_sym, options[meth])
      else
        self.send(meth)
      end
    end
  end

  validate!     if validate
  canonicalize! if canonicalize
end

Class Method Details

.add_entailment(method, proc) ⇒ Object

Add an entailment method. The method accepts no arguments, and returns or yields an array of values associated with the particular entailment method

Parameters:



13
14
15
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-reasoner-0705d0a3eca4/lib/rdf/reasoner/extensions.rb', line 13

def add_entailment(method, proc)
  @@entailments[method] = proc
end

.intern(str, *args) ⇒ RDF::URI

Returns an interned RDF::URI instance based on the given uri string.

The maximum number of cached interned URI references is given by the CACHE_SIZE constant. This value is unlimited by default, in which case an interned URI object will be purged only when the last strong reference to it is garbage collected (i.e., when its finalizer runs).

Excepting special memory-limited circumstances, it should always be safe and preferred to construct new URI references using RDF::URI.intern instead of RDF::URI.new, since if an interned object can't be returned for some reason, this method will fall back to returning a freshly-allocated one.

(see #initialize)

Returns:

  • (RDF::URI)

    an immutable, frozen URI object



144
145
146
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 144

def self.intern(str, *args)
  (cache[(str = str.to_s).to_sym] ||= self.new(str, *args)).freeze
end

.normalize_path(path) ⇒ String

TODO:

This process is correct, but overly iterative. It could be better done with a single regexp which handled most of the segment collapses all at once. Parent segments would still require iteration.

Resolve paths to their simplest form.

Parameters:

Returns:

  • (String)

    normalized path

See Also:



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 169

def self.normalize_path(path)
  output, input = "", path.to_s
  if input.encoding != Encoding::ASCII_8BIT
    input = input.dup if input.frozen?
    input = input.force_encoding(Encoding::ASCII_8BIT)
  end
  until input.empty?
    if input.match(RDS_2A)
      # If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
      input = $1
    elsif input.match(RDS_2B1) || input.match(RDS_2B2)
      # if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
      input = "/#{$1}"
    elsif input.match(RDS_2C1) || input.match(RDS_2C2)
      # if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer
      input = "/#{$1}"

      #  and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
      output.sub!(/\/?[^\/]*$/, '')
    elsif input.match(RDS_2D)
      # if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
      input = ""
    elsif input.match(RDS_2E)
      # move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer.end
      seg, input = $1, $2
      output << seg
    end
  end

  output.force_encoding(Encoding::UTF_8)
end

.parse(str) ⇒ RDF::URI

Creates a new RDF::URI instance based on the given uri string.

This is just an alias for #initialize for compatibity with Addressable::URI.parse. Actual parsing is defered until #object is accessed.

Parameters:

Returns:



157
158
159
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 157

def self.parse(str)
  self.new(str)
end

Instance Method Details

#+(other) ⇒ RDF::URI

Simple concatenation operator. Returns a URI formed from concatenating the string form of two elements.

For building URIs from fragments, you may want to use the smart separator, #/. #join implements another set of URI building semantics.

Examples:

Concatenating a string to a URI

RDF::URI.new('http://example.org/test') + 'test'
#=> RDF::URI('http://example.org/testtest')

Concatenating two URIs

RDF::URI.new('http://example.org/test') + RDF::URI.new('test')
#=> RDF::URI('http://example.org/testtest')

Parameters:

  • other (Any)

Returns:

See Also:



543
544
545
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 543

def +(other)
  RDF::URI.intern(self.to_s + other.to_s)
end

#/(fragment) ⇒ RDF::URI

'Smart separator' URI builder

This method attempts to use some understanding of the most common use cases for URLs and URNs to create a simple method for building new URIs from fragments. This means that it will always insert a separator of some sort, will remove duplicate seperators, will always assume that a fragment argument represents a relative and not absolute path, and throws an exception when an absolute URI is received for a fragment argument.

This is separate from the semantics for #join, which are well-defined by RFC3986 section 5.2 as part of the merging and normalization process; this method does not perform any normalization, removal of spurious paths, or removal of parent directory references (/../).

When fragment is a path segment containing a colon, best practice is to prepend a ./ and use #join, which resolves dot-segments.

See also #+, which concatenates the string forms of two URIs without any sort of checking or processing.

For an up-to-date list of edge case behavior, see the shared examples for RDF::URI in the rdf-spec project.

Examples:

Building a HTTP URL

RDF::URI.new('http://example.org') / 'jhacker' / 'foaf.ttl'
#=> RDF::URI('http://example.org/jhacker/foaf.ttl')

Building a HTTP URL (absolute path components)

RDF::URI.new('http://example.org/') / '/jhacker/' / '/foaf.ttl'
#=> RDF::URI('http://example.org/jhacker/foaf.ttl')

Using an anchored base URI

RDF::URI.new('http://example.org/users#') / 'jhacker'
#=> RDF::URI('http://example.org/users#jhacker')

Building a URN

RDF::URI.new('urn:isbn') / 125235111
#=> RDF::URI('urn:isbn:125235111')

Parameters:

  • fragment (Any)

    A URI fragment to be appended to this URI

Returns:

Raises:

  • (ArgumentError)

    if the URI is invalid

See Also:



488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 488

def /(fragment)
  frag = fragment.respond_to?(:to_uri) ? fragment.to_uri : RDF::URI(fragment.to_s)
  raise ArgumentError, "Non-absolute URI or string required, got #{frag}" unless frag.relative?
  if urn?
    RDF::URI.intern(to_s.sub(/:+$/,'') + ':' + fragment.to_s.sub(/^:+/,''))
  else # !urn?
    res = self.dup
    if res.fragment
      case fragment.to_s[0,1]
      when '/'
        # Base with a fragment, fragment beginning with '/'. The fragment wins, we use '/'.
        path, frag = fragment.to_s.split('#', 2)
        res.path = "#{res.path}/#{path.sub(/^\/*/,'')}"
        res.fragment = frag
      else
        # Replace fragment
        res.fragment = fragment.to_s.sub(/^#+/,'')
      end
    else
      # Not a fragment. includes '/'. Results from bases ending in '/' are the same as if there were no trailing slash.
      case fragment.to_s[0,1]
      when '#'
        # Base ending with '/', fragment beginning with '#'. The fragment wins, we use '#'.
        res.path = res.path.to_s.sub!(/\/*$/, '')
        # Add fragment
        res.fragment = fragment.to_s.sub(/^#+/,'')
      else
        # Add fragment as path component
        path, frag = fragment.to_s.split('#', 2)
        res.path = res.path.to_s.sub(/\/*$/,'/') + path.sub(/^\/*/,'')
        res.fragment = frag
      end
    end
    RDF::URI.intern(res.to_s)
  end
end

#==(other) ⇒ Boolean

Checks whether this URI is equal to other (type checking).

Per SPARQL data-r2/expr-equal/eq-2-2, numeric can't be compared with other types

Examples:

RDF::URI('http://t.co/') == RDF::URI('http://t.co/')    #=> true
RDF::URI('http://t.co/') == 'http://t.co/'              #=> true
RDF::URI('http://www.w3.org/2000/01/rdf-schema#') == RDF::RDFS        #=> true

Parameters:

Returns:

  • (Boolean)

    true or false

See Also:



721
722
723
724
725
726
727
728
729
730
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 721

def ==(other)
  case other
  when Literal
    # If other is a Literal, reverse test to consolodate complex type checking logic
    other == self
  when String then to_s == other
  when URI then hash == other.hash && to_s == other.to_s
  else other.respond_to?(:to_uri) && to_s == other.to_uri.to_s
  end
end

#===(other) ⇒ Boolean

Checks for case equality to the given other object.

Examples:

RDF::URI('http://example.org/') === /example/           #=> true
RDF::URI('http://example.org/') === /foobar/            #=> false
RDF::URI('http://t.co/') === RDF::URI('http://t.co/')   #=> true
RDF::URI('http://t.co/') === 'http://t.co/'             #=> true
RDF::URI('http://www.w3.org/2000/01/rdf-schema#') === RDF::RDFS       #=> true

Parameters:

Returns:

  • (Boolean)

    true or false

Since:

  • 0.3.0



745
746
747
748
749
750
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 745

def ===(other)
  case other
    when Regexp then other === to_s
    else self == other
  end
end

#=~(pattern) ⇒ Integer

Performs a pattern match using the given regular expression.

Examples:

RDF::URI('http://example.org/') =~ /example/            #=> 7
RDF::URI('http://example.org/') =~ /foobar/             #=> nil

Parameters:

Returns:

  • (Integer)

    the position the match starts

See Also:

  • String#=~

Since:

  • 0.3.0



763
764
765
766
767
768
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 763

def =~(pattern)
  case pattern
    when Regexp then to_s =~ pattern
    else super # `Object#=~` returns `false`
  end
end

#absolute?Boolean

A URI is absolute when it has a scheme

Returns:

  • (Boolean)

    true or false



306
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 306

def absolute?; !scheme.nil?; end

#authorityObject

Authority is a combination of user, password, host and port



1107
1108
1109
1110
1111
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1107

def authority
  object.fetch(:authority) {
    @object[:authority] = (format_authority if @object[:host])
  }
end

#authority=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



1116
1117
1118
1119
1120
1121
1122
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1116

def authority=(value)
  object.delete_if {|k, v| [:user, :password, :host, :port, :userinfo].include?(k)}
  object[:authority] = (value.to_s.force_encoding(Encoding::UTF_8) if value)
  user; password; userinfo; host; port
  @value = nil
  self
end

#canonicalizeRDF::URI Also known as: normalize

Returns a copy of this URI converted into its canonical lexical representation.

Returns:

Since:

  • 0.3.0



366
367
368
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 366

def canonicalize
  self.dup.canonicalize!
end

#canonicalize!RDF::URI Also known as: normalize!

Converts this URI into its canonical lexical representation.

Returns:

Since:

  • 0.3.0



376
377
378
379
380
381
382
383
384
385
386
387
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 376

def canonicalize!
  @object = {
    scheme: normalized_scheme,
    authority: normalized_authority,
    path: normalized_path.squeeze('/'),
    query: normalized_query,
    fragment: normalized_fragment
  }
  @value = nil
  @hash = nil
  self
end

#domain_compatible?(resource, queryable, options = {}) ⇒ Boolean

Determine if the domain of a property term is consistent with the specified resource in queryable.

Parameters:

Options Hash (options):

Returns:

  • (Boolean)


37
38
39
40
41
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-reasoner-0705d0a3eca4/lib/rdf/reasoner/extensions.rb', line 37

def domain_compatible?(resource, queryable, options = {})
  %w(owl rdfs schema).map {|r| "domain_compatible_#{r}?".to_sym}.all? do |meth|
    !self.respond_to?(meth) || self.send(meth, resource, queryable, options)
  end
end

#dupRDF::URI

Returns a duplicate copy of self.

Returns:



660
661
662
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 660

def dup
  self.class.new((@value || @object).dup)
end

#end_with?(string) ⇒ Boolean Also known as: ends_with?

Returns true if this URI ends with the given string.

Examples:

RDF::URI('http://example.org/').end_with?('/')          #=> true
RDF::URI('http://example.org/').end_with?('#')          #=> false

Parameters:

Returns:

  • (Boolean)

    true or false

See Also:

  • String#end_with?

Since:

  • 0.3.0



689
690
691
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 689

def end_with?(string)
  to_s.end_with?(string.to_s)
end

#entail(method) {|term| ... } ⇒ Array<Term>

Perform an entailment on this term.

Parameters:

  • method (Symbol)

    A registered entailment method

Yields:

  • term

Yield Parameters:

Returns:



25
26
27
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-reasoner-0705d0a3eca4/lib/rdf/reasoner/extensions.rb', line 25

def entail(method, &block)
  self.send(@@entailments.fetch(method), &block)
end

#eql?(other) ⇒ Boolean

Checks whether this URI the same term as other.

Examples:

RDF::URI('http://t.co/').eql?(RDF::URI('http://t.co/'))    #=> true
RDF::URI('http://t.co/').eql?('http://t.co/')              #=> false
RDF::URI('http://www.w3.org/2000/01/rdf-schema#').eql?(RDF::RDFS) #=> false

Parameters:

Returns:

  • (Boolean)

    true or false



704
705
706
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 704

def eql?(other)
  other.is_a?(URI) && self.hash == other.hash && self == other
end

#fragmentString

Returns:



1083
1084
1085
1086
1087
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1083

def fragment
  object.fetch(:fragment) do
    nil
  end
end

#fragment=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



1092
1093
1094
1095
1096
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1092

def fragment=(value)
  object[:fragment] = (value.to_s.force_encoding(Encoding::UTF_8) if value)
  @value = nil
  self
end

#has_parent?Boolean

Returns true if this URI is hierarchical and it's path component isn't equal to /.

Examples:

RDF::URI('http://example.org/').has_parent?             #=> false
RDF::URI('http://example.org/path/').has_parent?        #=> true

Returns:

  • (Boolean)

    true or false



589
590
591
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 589

def has_parent?
  !root?
end

#hashInteger

Returns a hash code for this URI.

Returns:



814
815
816
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 814

def hash
  @hash || @hash = (value.hash * -1)
end

#hier?Boolean

Returns true if the URI scheme is hierarchical.

Examples:

RDF::URI('http://example.org/').hier?                    #=> true
RDF::URI('urn:isbn:125235111').hier?                     #=> false

Returns:

  • (Boolean)

    true or false

See Also:

Since:

  • 1.0.10



286
287
288
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 286

def hier?
  !NON_HIER_SCHEMES.include?(scheme)
end

#hostString

Returns:



937
938
939
940
941
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 937

def host
  object.fetch(:host) do
    @object[:host] = ($1 if HOST_FROM_AUTHORITY_RE.match(@object[:authority]))
  end
end

#host=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



946
947
948
949
950
951
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 946

def host=(value)
  object[:host] = (value.to_s.force_encoding(Encoding::UTF_8) if value)
  @object[:authority] = format_authority
  @value = nil
  self
end

#inspectString

Returns a String representation of the URI object's state.

Returns:

  • (String)

    The URI object's state, as a String.



792
793
794
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 792

def inspect
  sprintf("#<%s:%#0x URI:%s>", URI.to_s, self.object_id, self.to_s)
end

#join(*uris) ⇒ RDF::URI

Joins several URIs together.

This method conforms to join normalization semantics as per RFC3986, section 5.2. This method normalizes URIs, removes some duplicate path information, such as double slashes, and other behavior specified in the RFC.

Other URI building methods are #/ and #+.

For an up-to-date list of edge case behavior, see the shared examples for RDF::URI in the rdf-spec project.

Examples:

Joining two URIs

RDF::URI.new('http://example.org/foo/bar').join('/foo')
#=> RDF::URI('http://example.org/foo')

Parameters:

Returns:

See Also:



414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 414

def join(*uris)
  joined_parts = object.dup.delete_if {|k, v| [:user, :password, :host, :port].include?(k)}

  uris.each do |uri|
    uri = RDF::URI.new(uri) unless uri.is_a?(RDF::URI)
    next if uri.to_s.empty? # Don't mess with base URI

    case
    when uri.scheme
      joined_parts = uri.object.merge(path: self.class.normalize_path(uri.path))
    when uri.authority
      joined_parts[:authority] = uri.authority
      joined_parts[:path] = self.class.normalize_path(uri.path)
      joined_parts[:query] = uri.query
    when uri.path.to_s.empty?
      joined_parts[:query] = uri.query if uri.query
    when uri.path[0,1] == '/'
      joined_parts[:path] = self.class.normalize_path(uri.path)
      joined_parts[:query] = uri.query
    else
      # Merge path segments from section 5.2.3
      base_path = path.to_s.sub(/\/[^\/]*$/, '/')
      joined_parts[:path] = self.class.normalize_path(base_path + uri.path)
      joined_parts[:query] = uri.query
    end
    joined_parts[:fragment] = uri.fragment
  end

  # Return joined URI
  RDF::URI.new(joined_parts)
end

#lengthInteger Also known as: size

Returns the string length of this URI.

Examples:

RDF::URI('http://example.org/').length                  #=> 19

Returns:

Since:

  • 0.3.0



333
334
335
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 333

def length
  to_s.length
end

#normalized_authorityString

Return normalized version of authority, if any

Returns:



1127
1128
1129
1130
1131
1132
1133
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1127

def normalized_authority
  if authority
    (userinfo ? normalized_userinfo.to_s + "@" : "") +
    normalized_host.to_s +
    (normalized_port ? ":" + normalized_port.to_s : "")
  end
end

#normalized_fragmentString

Normalized version of fragment

Returns:



1101
1102
1103
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1101

def normalized_fragment
  normalize_segment(fragment, IFRAGMENT) if fragment
end

#normalized_hostString

Normalized version of host

Returns:



956
957
958
959
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 956

def normalized_host
  # Remove trailing '.' characters
  normalize_segment(host, IHOST, true).chomp('.') if host
end

#normalized_passwordString

Normalized version of password

Returns:



929
930
931
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 929

def normalized_password
  ::URI.encode(::URI.decode(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/) if password
end

#normalized_pathString

Normalized version of path

Returns:



1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1021

def normalized_path
  segments = path.to_s.split('/', -1) # preserve null segments

  norm_segs = case
  when authority
    # ipath-abempty
    segments.map {|s| normalize_segment(s, ISEGMENT)}
  when segments[0].nil?
    # ipath-absolute
    res = [nil]
    res << normalize_segment(segments[1], ISEGMENT_NZ) if segments.length > 1
    res += segments[2..-1].map {|s| normalize_segment(s, ISEGMENT)} if segments.length > 2
    res
  when segments[0].to_s.index(':')
    # ipath-noscheme
    res = []
    res << normalize_segment(segments[0], ISEGMENT_NZ_NC)
    res += segments[1..-1].map {|s| normalize_segment(s, ISEGMENT)} if segments.length > 1
    res
  when segments[0]
    # ipath-rootless
    # ipath-noscheme
    res = []
    res << normalize_segment(segments[0], ISEGMENT_NZ)
    res += segments[1..-1].map {|s| normalize_segment(s, ISEGMENT)} if segments.length > 1
    res
  else
    # Should be empty
    segments
  end

  res = self.class.normalize_path(norm_segs.join("/"))
  # Special rules for specific protocols having empty paths
  normalize_segment(res.empty? ? (%w(http https ftp tftp).include?(normalized_scheme) ? '/' : "") : res, IHIER_PART)
end

#normalized_portString

Normalized version of port

Returns:



984
985
986
987
988
989
990
991
992
993
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 984

def normalized_port
  if port
    np = normalize_segment(port.to_s, PORT)
    if PORT_MAPPING[normalized_scheme] == np.to_i
      nil
    else
      np.to_i
    end
  end
end

#normalized_queryString

Normalized version of query

Returns:



1077
1078
1079
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1077

def normalized_query
  normalize_segment(query, IQUERY) if query
end

#normalized_schemeString

Return normalized version of scheme, if any

Returns:



877
878
879
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 877

def normalized_scheme
  normalize_segment(scheme.strip, SCHEME, true) if scheme
end

#normalized_userString

Normalized version of user

Returns:



903
904
905
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 903

def normalized_user
  ::URI.encode(::URI.decode(user), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/) if user
end

#normalized_userinfoString

Normalized version of userinfo

Returns:



1157
1158
1159
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1157

def normalized_userinfo
  normalized_user + (password ? ":#{normalized_password}" : "") if userinfo
end

#objectHash{Symbol => String} Also known as: to_h

Returns object representation of this URI, broken into components

Returns:



822
823
824
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 822

def object
  @object || @object = parse(@value)
end

#parentRDF::URI

Returns a copy of this URI with the path component ascended to the parent directory, if any.

Examples:

RDF::URI('http://example.org/').parent                  #=> nil
RDF::URI('http://example.org/path/').parent             #=> RDF::URI('http://example.org/')

Returns:



602
603
604
605
606
607
608
609
610
611
612
613
614
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 602

def parent
  case
    when root? then nil
    else
      require 'pathname' unless defined?(Pathname)
      if path = Pathname.new(self.path).parent
        uri = self.dup
        uri.path = path.to_s
        uri.path << '/' unless uri.root?
        uri
      end
  end
end

#parse(value) ⇒ Object{Symbol => String}

{ Parse a URI into it's components

Parameters:

Returns:



832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 832

def parse(value)
  value = value.to_s.dup.force_encoding(Encoding::ASCII_8BIT)
  parts = {}
  if matchdata = IRI_PARTS.match(value)
    scheme, authority, path, query, fragment = matchdata[1..-1]
    userinfo, hostport = authority.to_s.split('@', 2)
    hostport, userinfo = userinfo, nil unless hostport
    user, password = userinfo.to_s.split(':', 2)
    host, port = hostport.to_s.split(':', 2)

    parts[:scheme] = (scheme.force_encoding(Encoding::UTF_8) if scheme)
    parts[:authority] = (authority.force_encoding(Encoding::UTF_8) if authority)
    parts[:userinfo] = (userinfo.force_encoding(Encoding::UTF_8) if userinfo)
    parts[:user] = (user.force_encoding(Encoding::UTF_8) if user)
    parts[:password] = (password.force_encoding(Encoding::UTF_8) if password)
    parts[:host] = (host.force_encoding(Encoding::UTF_8) if host)
    parts[:port] = (::URI.decode(port).to_i if port)
    parts[:path] = (path.to_s.force_encoding(Encoding::UTF_8) unless path.empty?)
    parts[:query] = (query[1..-1].force_encoding(Encoding::UTF_8) if query)
    parts[:fragment] = (fragment[1..-1].force_encoding(Encoding::UTF_8) if fragment)
  end
  
  parts
end

#passwordString

Returns:



909
910
911
912
913
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 909

def password
  object.fetch(:password) do
    @object[:password] = (userinfo.split(':', 2)[1] if userinfo)
  end
end

#password=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



918
919
920
921
922
923
924
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 918

def password=(value)
  object[:password] = (value.to_s.force_encoding(Encoding::UTF_8) if value)
  @object[:userinfo] = format_userinfo("")
  @object[:authority] = format_authority
  @value = nil
  self
end

#pathString

Returns:



997
998
999
1000
1001
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 997

def path
  object.fetch(:path) do
    nil
  end
end

#path=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1006

def path=(value)
  if value
    # Always lead with a slash
    value = "/#{value}" if host && value.to_s =~ /^[^\/]/
    object[:path] = value.to_s.force_encoding(Encoding::UTF_8)
  else
    object[:path] = nil
  end
  @value = nil
  self
end

#pnameString

Returns a string version of the QName or the full IRI

Returns:



652
653
654
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 652

def pname
  (q = self.qname) ? q.join(":") : to_s
end

#portString

Returns:



965
966
967
968
969
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 965

def port
  object.fetch(:port) do
    @object[:port] = ($1 if PORT_FROM_AUTHORITY_RE.match(@object[:authority]))
  end
end

#port=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



974
975
976
977
978
979
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 974

def port=(value)
  object[:port] = (value.to_s.to_i if value)
  @object[:authority] = format_authority
  @value = nil
  self
end

#qnameArray(Symbol, Symbol)

Returns a qualified name (QName) for this URI based on available vocabularies, if possible.

Examples:

RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname       #=> [:rdfs, nil]
RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname  #=> [:rdfs, :label]
RDF::RDFS.label.qname                                         #=> [:rdfs, :label]

Returns:



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 625

def qname
  if self.to_s =~ %r([:/#]([^:/#]*)$)
    local_name = $1
    vocab_uri  = local_name.empty? ? self.to_s : self.to_s[0...-(local_name.length)]
    Vocabulary.each do |vocab|
      if vocab.to_uri == vocab_uri
        prefix = vocab.equal?(RDF) ? :rdf : vocab.__prefix__
        return [prefix, local_name.empty? ? nil : local_name.to_sym]
      end
    end
  else
    Vocabulary.each do |vocab|
      vocab_uri = vocab.to_uri
      if self.start_with?(vocab_uri)
        prefix = vocab.equal?(RDF) ? :rdf : vocab.__prefix__
        local_name = self.to_s[vocab_uri.length..-1]
        return [prefix, local_name.empty? ? nil : local_name.to_sym]
      end
    end
  end
  return nil # no QName found
end

#queryString

Returns:



1059
1060
1061
1062
1063
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1059

def query
  object.fetch(:query) do
    nil
  end
end

#query=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



1068
1069
1070
1071
1072
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1068

def query=(value)
  object[:query] = (value.to_s.force_encoding(Encoding::UTF_8) if value)
  @value = nil
  self
end

#query_values(return_type = Hash) ⇒ Hash, Array

Converts the query component to a Hash value.

Examples:

RDF::URI.new("?one=1&two=2&three=3").query_values
#=> {"one" => "1", "two" => "2", "three" => "3"}
RDF::URI.new("?one=two&one=three").query_values(Array)
#=> [["one", "two"], ["one", "three"]]
RDF::URI.new("?one=two&one=three").query_values(Hash)
#=> {"one" => ["two", "three"]}

Parameters:

  • return_type (Class) (defaults to: Hash)

    (Hash) The return type desired. Value must be either # Hash or Array.

Returns:

  • (Hash, Array)

    The query string parsed as a Hash or Array object.

Raises:

  • (ArgumentError)


1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1175

def query_values(return_type=Hash)
  raise ArgumentError, "Invalid return type. Must be Hash or Array." unless [Hash, Array].include?(return_type)
  return nil if query.nil?
  query.to_s.split('&').
    inject(return_type == Hash ? {} : []) do |memo,kv|
      k,v = kv.to_s.split('=', 2)
      next if k.to_s.empty?
      k = ::URI.decode(k)
      v = ::URI.decode(v) if v
      if return_type == Hash
        case memo[k]
        when nil then memo[k] = v
        when Array then memo[k] << v
        else memo[k] = [memo[k], v]
        end
      else
        memo << [k, v].compact
      end
      memo
    end
end

#query_values=(value) ⇒ Object

Sets the query component for this URI from a Hash object. An empty Hash or Array will result in an empty query string.

Examples:

Hash with single and array values

uri.query_values = {a: "a", b: ["c", "d", "e"]}
uri.query
# => "a=a&b=c&b=d&b=e"

Array with Array values including repeated variables

uri.query_values = [['a', 'a'], ['b', 'c'], ['b', 'd'], ['b', 'e']]
uri.query
# => "a=a&b=c&b=d&b=e"

Array with Array values including multiple elements

uri.query_values = [['a', 'a'], ['b', ['c', 'd', 'e']]]
uri.query
# => "a=a&b=c&b=d&b=e"

Array with Array values having only one entry

uri.query_values = [['flag'], ['key', 'value']]
uri.query
# => "flag&key=value"

Parameters:

  • value (Hash, #to_hash, Array)

    The new query values.



1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1222

def query_values=(value)
  if value.nil?
    self.query = nil
    return
  end

  value = value.to_hash if value.respond_to?(:to_hash)
  self.query = case value
  when Array, Hash
    value.map do |(k,v)|
      k = normalize_segment(k.to_s, UNRESERVED)
      if v.nil?
        k
      else
        Array(v).map do |vv|
          if vv === TrueClass
            k
          else
            "#{k}=#{normalize_segment(vv.to_s, UNRESERVED)}"
          end
        end.join("&")
      end
    end
  else
    raise TypeError,
      "Can't convert #{value.class} into Hash."
  end.join("&")
end

#range_compatible?(resource, queryable, options = {}) ⇒ Boolean

Determine if the range of a property term is consistent with the specified resource in queryable.

Specific entailment regimes should insert themselves before this to apply the appropriate semantic condition

Parameters:

Options Hash (options):

Returns:

  • (Boolean)


53
54
55
56
57
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-reasoner-0705d0a3eca4/lib/rdf/reasoner/extensions.rb', line 53

def range_compatible?(resource, queryable, options = {})
  %w(owl rdfs schema).map {|r| "range_compatible_#{r}?".to_sym}.all? do |meth|
    !self.respond_to?(meth) || self.send(meth, resource, queryable, options)
  end
end

#relative?Boolean

A URI is relative when it does not have a scheme

Returns:

  • (Boolean)

    true or false



311
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 311

def relative?; !absolute?; end

#relativize(base_uri) ⇒ RDF::URI

Attempt to make this URI relative to the provided base_uri. If successful, returns a relative URI, otherwise the original URI

Parameters:

Returns:



316
317
318
319
320
321
322
323
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 316

def relativize(base_uri)
  if base_uri.to_s.end_with?("/", "#") &&
     self.to_s.start_with?(base_uri.to_s)
    RDF::URI(self.to_s[base_uri.to_s.length..-1])
  else
    self
  end
end

#request_uriString

The HTTP request URI for this URI. This is the path and the query string.

Returns:

  • (String)

    The request URI required for an HTTP request.



1256
1257
1258
1259
1260
1261
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1256

def request_uri
  return nil if absolute? && scheme !~ /^https?$/
  res = path.to_s.empty? ? "/" : path
  res += "?#{self.query}" if self.query
  return res
end

#rootRDF::URI

Returns a copy of this URI with the path component set to /.

Examples:

RDF::URI('http://example.org/').root                    #=> RDF::URI('http://example.org/')
RDF::URI('http://example.org/path/').root               #=> RDF::URI('http://example.org/')

Returns:



571
572
573
574
575
576
577
578
579
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 571

def root
  if root?
    self
  else
    RDF::URI.new(
      object.merge(path: '/').
      keep_if {|k, v| [:scheme, :authority, :path].include?(k)})
  end
end

#root?Boolean

Returns true if this URI's scheme is not hierarchical, or its path component is equal to /. Protocols not using hierarchical components are always considered to be at the root.

Examples:

RDF::URI('http://example.org/').root?                   #=> true
RDF::URI('http://example.org/path/').root?              #=> false
RDF::URI('urn:isbn').root?                              #=> true

Returns:

  • (Boolean)

    true or false



559
560
561
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 559

def root?
  !self.hier?  || self.path == '/' || self.path.to_s.empty?
end

#schemeString

Returns:



859
860
861
862
863
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 859

def scheme
  object.fetch(:scheme) do
    nil
  end
end

#scheme=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



868
869
870
871
872
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 868

def scheme=(value)
  object[:scheme] = (value.to_s.force_encoding(Encoding::UTF_8) if value)
  @value = nil
  self
end

#to_strString Also known as: to_s

Returns the string representation of this URI.

Examples:

RDF::URI('http://example.org/').to_str                  #=> 'http://example.org/'

Returns:



785
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 785

def to_str; value; end

#to_uriRDF::URI

Returns self.

Returns:



774
775
776
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 774

def to_uri
  self
end

#uri?Boolean

Returns true.

Returns:

  • (Boolean)

    true or false

See Also:



258
259
260
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 258

def uri?
  true
end

#url?Boolean

Returns true if this URI is a URL.

Examples:

RDF::URI('http://example.org/').url?                    #=> true

Returns:

  • (Boolean)

    true or false

See Also:

Since:

  • 0.2.0



299
300
301
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 299

def url?
  !urn?
end

#urn?Boolean

Returns true if this URI is a URN.

Examples:

RDF::URI('http://example.org/').urn?                    #=> false

Returns:

  • (Boolean)

    true or false

See Also:

Since:

  • 0.2.0



271
272
273
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 271

def urn?
  @object ? @object[:scheme] == 'urn' : start_with?('urn:')
end

#userString

Returns:



883
884
885
886
887
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 883

def user
  object.fetch(:user) do
    @object[:user] = (userinfo.split(':', 2)[0] if userinfo)
  end
end

#user=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



892
893
894
895
896
897
898
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 892

def user=(value)
  object[:user] = (value.to_s.force_encoding(Encoding::UTF_8) if value)
  @object[:userinfo] = format_userinfo("")
  @object[:authority] = format_authority
  @value = nil
  self
end

#userinfoObject

Userinfo is a combination of user and password



1137
1138
1139
1140
1141
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1137

def userinfo
  object.fetch(:userinfo) {
    @object[:userinfo] = (format_userinfo("") if @object[:user])
  }
end

#userinfo=(value) ⇒ RDF::URI

Returns self

Parameters:

Returns:



1146
1147
1148
1149
1150
1151
1152
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 1146

def userinfo=(value)
  object.delete_if {|k, v| [:user, :password, :authority].include?(k)}
  object[:userinfo] = (value.to_s.force_encoding(Encoding::UTF_8) if value)
  user; password; authority
  @value = nil
  self
end

#valid?Boolean

Determine if the URI is a valid according to RFC3987

Note that RDF URIs syntactically can contain Unicode escapes, which are unencoded in the internal representation. To validate, %-encode specifically excluded characters from IRIREF

Returns:

  • (Boolean)

    true or false

Since:

  • 0.3.9



345
346
347
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 345

def valid?
  RDF::URI::IRI.match(to_s) || false
end

#valid_extended?Boolean

Validate extended RDF

Returns:

  • (Boolean)


23
24
25
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/json-ld-5d3887dcf198/lib/json/ld/extensions.rb', line 23

def valid_extended?
  self.valid?
end

#validate!RDF::URI

Validates this URI, raising an error if it is invalid.

Returns:

Raises:

  • (ArgumentError)

    if the URI is invalid

Since:

  • 0.3.0



355
356
357
358
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 355

def validate!
  raise ArgumentError, "#{to_base.inspect} is not a valid IRI" if invalid?
  self
end

#valueString

lexical representation of URI, either absolute or relative

Returns:



799
800
801
802
803
804
805
806
807
808
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/model/uri.rb', line 799

def value
  return @value if @value
  @value = [
    ("#{scheme}:" if absolute?),
    ("//#{authority}" if authority),
    path,
    ("?#{query}" if query),
    ("##{fragment}" if fragment)
  ].compact.join("").freeze
end