Redland RDF Application Framework - Ruby RDoc - Class: Redland::Node

Go to Redland Home - Language Bindings Home - Ruby API Home

Class | Redland::Node
In: | rdf/redland/node.rb
Parent: | Object

### Methods

== anon blank? blank_identifier bnode create_finalizer ensure literal literal? new node_from_hash node_from_literal node_type resource? to_s uri

### Attributes

node | [R] |

### Public Class methods

anon(id)

Creates a new blank node with the specified ID (?? confirm)

[Source]

    # File rdf/redland/node.rb, line 84
        def Node.anon(id)
          n = Node.new('')
          n.bnode(id)
          n
        end

create_finalizer(node)

You shouldn‘t use this. Used internally for cleanup.

[Source]

    # File rdf/redland/node.rb, line 79
        def Node.create_finalizer(node)
          proc {|id| Redland::librdf_free_node(node) }
        end

ensure(node)

Ensures that the argument is a node by constructing one or returning nil (?? confirm)

[Source]

    # File rdf/redland/node.rb, line 158
        def Node.ensure(node)
          case node
          when Node
            my_node = Redland.librdf_new_node_from_node(node.node)
          when SWIG::TYPE_p_librdf_node_s
            my_node = Redland.librdf_new_node_from_node(node)
          when Uri
            my_node = Redland.librdf_new_node_from_uri($world.world,node.uri)
          when URI
            my_node = Redland.librdf_new_node_from_uri_string($world.world,node.to_s)
          else
            my_node = nil
          end
          return my_node
        end

new(arg=nil)

Create an RDF Node

Resource or property node creation

      n1 = Node.new(Uri.new("http://example.com/foo"))

String literal node creation

      n2 = Node.new("foo")

[Source]

    # File rdf/redland/node.rb, line 21
        def initialize(arg=nil)
          if arg.class == String
            temp = arg
            arg = {}
            arg[:literal]= temp
            @node = self.node_from_hash(arg)
          elsif arg.class == Hash
            @node = node_from_hash(arg)
          else
            @node = Node.ensure(arg)
          end
          raise RedlandError.new("Node construction failed") if not @node
          ObjectSpace.define_finalizer(self,Node.create_finalizer(@node))
        end

### Public Instance methods

==(other)

Equivalency. Only works for comparing two Nodes

[Source]

    # File rdf/redland/node.rb, line 106
        def ==(other)
          return (Redland.librdf_node_equals(self.node,other.node) != 0)
        end

blank?()

Return true if node is a blank node

[Source]

    # File rdf/redland/node.rb, line 101
        def blank?
          return (Redland.librdf_node_is_blank(self.node) !=0)
        end

blank_identifier()

returns the blank identifier for this node if the internal model is a blank node

[Source]

    # File rdf/redland/node.rb, line 148
        def blank_identifier()
          unless self.blank?
            raise NodeTypeError.new("Can't get blank identifier for node type %s" % self.node_type)
          else
            return Redland.librdf_node_get_blank_identifier(self.node)
          end
        end

bnode(id=nil)

Sets this node‘s value to a blank node with the specified ID (?? confirm)

[Source]

    # File rdf/redland/node.rb, line 74
        def bnode(id=nil)
          @node = Redland.librdf_new_node_from_blank_identifier($world.world,id)
        end

literal()

returns a Literal if the node is a literal type

[Source]

    # File rdf/redland/node.rb, line 139
        def literal
          unless self.literal?
            raise NodeTypeError.new("Can't get literal value for node type %s" % self.node_type)
          end
          return Literal.from_node(self.node)
        end

literal?()

Return true if node is a literal

[Source]

    # File rdf/redland/node.rb, line 91
        def literal?
          return (Redland.librdf_node_is_literal(self.node) !=0)
        end

node_from_hash(hash)

sets this node‘s value using a blank or URI extracted from a Hash (?? confirm)

[Source]

    # File rdf/redland/node.rb, line 38
        def node_from_hash(hash)
          if hash.key?(:blank)
            node = Redland.librdf_new_node_from_blank_identifier($world.world,hash[:blank])
          end
          if hash.key?(:from_object)
            if hash.key?(:do_not_copy)
              node = hash[:from_object]
            else
              node = Redland.librdf_new_node_from_node(hash[:from_object])
            end
          end

          if hash.key?(:uri_string)
            node = Redland.librdf_new_node_from_uri_string($world.world,hash[:uri_string])
          end
          if hash.key?(:literal)
            node = node_from_literal(hash)
          end
          return node
        end

node_from_literal(hash)

sets this node‘s value using a literal value extracted from a Hash (?? confirm)

[Source]

    # File rdf/redland/node.rb, line 61
        def node_from_literal(hash)
          xml_language = hash.key?(:xml_language) ? hash[:xml_language] : ""
          wf_xml = hash.key?(:wf_xml?) ? 1 : 0
          if hash.key?(:datatype)
            datatype = hash[:datatype]
            node = Redland.librdf_new_node_from_typed_literal($world.world,hash[:literal],xml_language,datatype.uri)
          else
            node = Redland.librdf_new_node_from_literal($world.world,hash[:literal],xml_language,wf_xml)
          end
          return node
        end

node_type()

Get the type of this node as a string (Node.node_types)

[Source]

    # File rdf/redland/node.rb, line 125
        def node_type()
          return @@node_types[Redland.librdf_node_get_type(self.node)]
        end

resource?()

Return true if node is a resource with a URI

[Source]

    # File rdf/redland/node.rb, line 96
        def resource?
          return (Redland.librdf_node_is_resource(self.node) !=0)
        end

to_s()

Convert this to a string

[Source]

    # File rdf/redland/node.rb, line 111
        def to_s
          if self.literal?
            Redland.librdf_node_get_literal_value(self.node)
          elsif self.blank?
            Redland.librdf_node_get_blank_identifier(self.node)
          elsif self.resource?
            uri = Redland.librdf_node_get_uri(self.node)
            Redland.librdf_uri_to_string(uri) unless uri.nil?
          else
            nil
          end
        end

uri()

return a copy of the internal uri

[Source]

    # File rdf/redland/node.rb, line 130
        def uri
          if self.resource?
            return Uri.new(Redland.librdf_node_get_uri(self.node))
          else
            raise NodeTypeError.new("Can't get URI for node type %s" % self.node_type() )
          end
        end

Go to Redland Home - Language Bindings Home - Ruby API Home

(C) Copyright 2004-2011 Dave Beckett, (C) Copyright 2004-2005 University of Bristol