semantic_naming 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/semantic_naming/uri.rb +15 -0
- data/test/uri_test.rb +10 -0
- metadata +2 -2
data/lib/semantic_naming/uri.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
1
3
|
module N
|
2
4
|
|
3
5
|
# This class contains basic functionality for URIs
|
@@ -251,6 +253,19 @@ module N
|
|
251
253
|
self.clone
|
252
254
|
end
|
253
255
|
|
256
|
+
# Encodes the uri in a modified base64 format that will always form a legal
|
257
|
+
# HTML id tag.
|
258
|
+
def safe_encoded
|
259
|
+
'uri_' << Base64.encode64(@uri_s).gsub(/==\s*\Z/, '').gsub('+', '_').gsub('/', '-')
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
# Creates a new URI object from a string that was encoded with #safe_encoded
|
264
|
+
def self.from_encoded(encoded_uri)
|
265
|
+
uri = Base64.decode64(encoded_uri.gsub(/\Auri_/, '').gsub('_', '+').gsub('-', '/') + '==')
|
266
|
+
self.new(uri)
|
267
|
+
end
|
268
|
+
|
254
269
|
private
|
255
270
|
|
256
271
|
# Check if the ActiveRDF library is present.
|
data/test/uri_test.rb
CHANGED
@@ -224,6 +224,16 @@ class URITest < Test::Unit::TestCase
|
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
|
+
def test_encode_uri
|
228
|
+
uri = N::URI.new(N::RDFTEST::encoding)
|
229
|
+
assert_equal('uri_aHR0cDovL3JkZnRlc3RkdW1teS9lbmNvZGluZw', uri.safe_encoded)
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_from_encoded
|
233
|
+
uri = N::URI.from_encoded('uri_aHR0cDovL3JkZnRlc3RkdW1teS9lbmNvZGluZw')
|
234
|
+
assert_equal(N::RDFTEST::encoding, uri)
|
235
|
+
end
|
236
|
+
|
227
237
|
def test_to_name_s
|
228
238
|
assert_equal('rdftest:foo', N::RDFTEST.foo.to_name_s)
|
229
239
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_naming
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Hahn
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-09 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|