This repository has been archived by the owner on Sep 12, 2018. It is now read-only.
forked from ruby-rdf/spira
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|