Skip to content
This repository has been archived by the owner on Dec 21, 2017. It is now read-only.

Commit

Permalink
we now have working namespace->graph binding
Browse files Browse the repository at this point in the history
  • Loading branch information
tommorris committed Jul 9, 2008
1 parent 249a010 commit 5855b8f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
require 'lib/literal'
require 'lib/triple'
class Graph
attr_accessor :triples
attr_accessor :triples, :nsbinding

def initialize
@triples = []
@nsbinding = []
@nsbinding = {}
end

def size
Expand Down Expand Up @@ -38,7 +38,7 @@ def namespace(uri, short)

def bind(namespace)
if namespace.class == Namespace
@nsbinding =+ namespace
@nsbinding["#{namespace.short}"] = namespace
else
raise
end
Expand Down
5 changes: 4 additions & 1 deletion lib/namespace.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'lib/uriref'
require 'lib/graph'

class Namespace
attr_accessor :short, :uri

def initialize(uri, short)
@uri = uri
if shortname_valid?(short)
Expand All @@ -15,7 +18,7 @@ def method_missing(methodname, *args)
end

def bind(graph)
if graph.class == Class
if graph.class == Graph
graph.bind(self)
else
raise
Expand Down
7 changes: 6 additions & 1 deletion test/spec/namespaces.spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'lib/graph'
require 'lib/namespace'

describe "Namespaces" do
it "should use method_missing to create URIRefs on the fly" do
foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf")
Expand All @@ -18,7 +20,10 @@
end

it "should be able to attach to the graph for substitution" do
pending "TODO: looking at best way to do this"
# rdflib does this using graph.bind('prefix', namespace)
g = Graph.new
foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf")
foaf.bind(g)
g.nsbinding["foaf"].should == foaf
end
end

0 comments on commit 5855b8f

Please sign in to comment.