Class: RDF::Raptor::FFI::V1::URI

Inherits:
FFI::ManagedStruct
  • Object
show all
Includes:
RDF::Raptor::FFI, RDF::Resource
Defined in:
lib/rdf/raptor/ffi/v1/uri.rb

Overview

Raptor has a raptor_uri class which must be used for manipulating and passing URI references. The default internal implementation uses char* strings for URIs, manipulating them and constructing them.

Constant Summary

Constants included from RDF::Raptor::FFI

ENGINE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RDF::Raptor::FFI

#version

Constructor Details

#initialize(ptr) ⇒ URI #initialize(name) ⇒ URI

Returns a new instance of URI.

Overloads:

  • #initialize(ptr) ⇒ URI

    Parameters:

    • ptr (FFI::Pointer)
  • #initialize(name) ⇒ URI

    Parameters:

    • name (RDF::URI, String)

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 20

def initialize(ptr_or_name)
  ptr = case ptr_or_name
    when FFI::Pointer then ptr_or_name
    when RDF::URI     then V1.raptor_new_uri(ptr_or_name.to_s)
    when String       then V1.raptor_new_uri(ptr_or_name)
    else nil
  end
  raise ArgumentError, "invalid argument: #{ptr_or_name.inspect}" if ptr.nil? || ptr.null?
  super(ptr)
end

Class Method Details

.release(ptr)

This method returns an undefined value.

Releases libraptor memory associated with this structure.

Parameters:

  • ptr (FFI::Pointer)


36
37
38
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 36

def self.release(ptr)
  V1.raptor_free_uri(ptr)
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: ===

Returns true or false.

Returns:

  • (Boolean)

    true or false



72
73
74
75
76
77
78
79
80
81
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 72

def ==(other)
  return true if self.equal?(other)
  case other
    when self.class
      !(V1.raptor_uri_equals(self, other).zero?)
    when RDF::URI, String
      to_str == other.to_str
    else false
  end
end

#cloneURI

Returns a copy of self.

Returns:

  • (URI)

    a copy of self



56
57
58
59
60
61
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 56

def clone
  copy = self.class.new(V1.raptor_uri_copy(self))
  copy.taint  if tainted?
  copy.freeze if frozen?
  copy
end

#dupURI

Returns a copy of self.

Returns:

  • (URI)

    a copy of self



48
49
50
51
52
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 48

def dup
  copy = self.class.new(V1.raptor_uri_copy(self))
  copy.taint if tainted?
  copy
end

#eql?(other) ⇒ Boolean

Returns true or false.

Returns:

  • (Boolean)

    true or false



86
87
88
89
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 86

def eql?(other)
  return true if self.equal?(other)
  other.is_a?(self.class) && !(V1.raptor_uri_equals(self, other).zero?)
end

#hashFixnum

Returns:

  • (Fixnum)


93
94
95
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 93

def hash
  to_str.hash
end

#lengthInteger Also known as: size

Returns:

  • (Integer)


65
66
67
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 65

def length
  LibC.strlen(self)
end

#to_rdfRDF::URI Also known as: to_uri

Returns:

  • (RDF::URI)


106
107
108
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 106

def to_rdf
  RDF::URI.intern(to_str)
end

#to_strString Also known as: to_s

Returns the URI string.

Returns:

  • (String)

    the URI string



99
100
101
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 99

def to_str
  V1.raptor_uri_as_string(self)
end

#uri?Boolean

Returns true.

Returns:

  • (Boolean)

    true



42
43
44
# File 'lib/rdf/raptor/ffi/v1/uri.rb', line 42

def uri?
  true
end