Redland RDF Language Bindings - Ruby RDoc - Class: Redland::Node

### Home Classes Methods

### In Files

- rdf/redland/node.rb

### Parent

Object

### Methods

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

### Files

- Makefile
- Makefile
- Makefile
- Makefile

### Class/Module Index

Quicksearch

- Redland
- Redland::BNode
- Redland::ContextParser
- Redland::FileStore
- Redland::HashOpen
- Redland::HashStore
- Redland::Literal
- Redland::MemoryStore
- Redland::MergedModel
- Redland::Model
- Redland::Namespace
- Redland::Node
- Redland::NodeIterator
- Redland::NodeTypeError
- Redland::OWL
- Redland::Parser
- Redland::Query
- Redland::QueryResults
- Redland::RDFS
- Redland::RedlandError
- Redland::Resource
- Redland::Serializer
- Redland::Statement
- Redland::Stream
- Redland::TripleStore
- Redland::Uri
- Redland::Util
- Redland::World
- DC
- FOAF

No matching classes.

# Redland::Node

### Attributes

node[R]

### Public Class Methods

anon(id) click to toggle source

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

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

create_finalizer(node) click to toggle source

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

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

ensure(node) click to toggle source

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

    # 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) click to toggle source

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")

    # 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) click to toggle source

Equivalency. Only works for comparing two Nodes

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

blank?() click to toggle source

Return true if node is a blank node

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

blank_identifier() click to toggle source

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

    # 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) click to toggle source

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

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

literal() click to toggle source

returns a Literal if the node is a literal type

    # 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?() click to toggle source

Return true if node is a literal

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

node_from_hash(hash) click to toggle source

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

    # 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) click to toggle source

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

    # 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() click to toggle source

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

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

resource?() click to toggle source

Return true if node is a resource with a URI

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

to_s() click to toggle source

Convert this to a string

    # 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() click to toggle source

return a copy of the internal uri

    # 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-2013 Dave Beckett, (C) Copyright 2004-2005 University of Bristol