Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Implement Spira::Types::URI
Browse files Browse the repository at this point in the history
  • Loading branch information
bhuga committed Jun 2, 2010
1 parent f4d2e77 commit 06a33c3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/spira/types.rb
Expand Up @@ -19,6 +19,7 @@ module Types
require 'spira/types/any'
require 'spira/types/string'
require 'spira/types/float'
require 'spira/types/uri'


end
Expand Down
25 changes: 25 additions & 0 deletions lib/spira/types/uri.rb
@@ -0,0 +1,25 @@
module Spira::Types

##
# This type takes RDF Resource objects and provides RDF::URI objects for the
# ruby representation.
#
# @see Spira::Type
# @see http://rdf.rubyforge.org/RDF/URI.html
class URI

include Spira::Type

def self.unserialize(value)
RDF::URI(value)
end

def self.serialize(value)
RDF::URI(value)
end

register_alias :uri
register_alias RDF::URI

end
end
40 changes: 40 additions & 0 deletions spec/types/uri.spec
@@ -0,0 +1,40 @@
require File.dirname(__FILE__) + "/../spec_helper.rb"

describe Spira::Types::URI do

before :each do
@uri = RDF::URI('http://example.org/example')
end

context "when serializing" do
it "should serialize URIs to URIs" do
serialized = Spira::Types::URI.serialize(@uri)
serialized.should be_a RDF::URI
serialized.should == @uri
end

it "should serialize non-URIs to URIs based on the URI constructor" do
serialized = Spira::Types::URI.serialize("test")
serialized.should be_a RDF::URI
serialized.should == RDF::URI('test')
end

end

context "when unserializing" do
it "should unserialize URIs to themselves" do
value = Spira::Types::URI.unserialize(@uri)
value.should be_a RDF::URI
value.should == @uri
end

it "should unserialize non-URIs to URIs based on the URI constructor" do
value = Spira::Types::URI.unserialize("test")
value.should be_a RDF::URI
value.should == RDF::URI('test')
end
end


end

0 comments on commit 06a33c3

Please sign in to comment.