iq_rdf 0.1.4 → 0.1.5

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.
@@ -16,7 +16,7 @@ module IqRdf
16
16
  class Literal
17
17
 
18
18
  def initialize(obj, lang = nil, datatype = nil)
19
- raise "#{datatype.inspect} is not an URI" if datatype && !datatype.is_a?(::URI)
19
+ raise "#{datatype.inspect} is not an URI" unless datatype.nil? || datatype.is_a?(::URI) || datatype.is_a?(IqRdf::Uri)
20
20
  @obj = obj
21
21
  @datatype = datatype
22
22
  @lang = lang
@@ -36,15 +36,26 @@ module IqRdf
36
36
 
37
37
  def to_s(parent_lang = nil)
38
38
  lang = @lang || parent_lang # Use the Literals lang when given
39
+ lang = (lang && lang != :none) ? "@#{lang}" : ""
39
40
  quote = @obj.to_s.include?("\n") ? '"""' : '"'
40
- "#{quote}#{@obj.to_s.gsub("\\", "\\\\\\\\").gsub(/"/, "\\\"")}#{quote}" <<
41
- ((lang && lang != :none) ? "@#{lang}" : "") <<
42
- (@datatype ? "^^<#{@datatype.to_s}>" : "")
41
+ datatype = if @datatype.is_a?(::URI)
42
+ "^^<#{@datatype.to_s}>"
43
+ elsif @datatype.is_a?(IqRdf::Uri)
44
+ "^^#{@datatype.to_s}"
45
+ else
46
+ ""
47
+ end
48
+
49
+ "#{quote}#{@obj.to_s.gsub("\\", "\\\\\\\\").gsub(/"/, "\\\"")}#{quote}#{lang}#{datatype}"
43
50
  end
44
51
 
45
52
  def build_xml(xml, &block)
46
53
  opts = {}
47
- opts["rdf:datatype"] = @datatype.to_s if @datatype
54
+ if @datatype.is_a?(::URI)
55
+ opts["rdf:datatype"] = @datatype.to_s
56
+ elsif @datatype.is_a?(IqRdf::Uri)
57
+ opts["rdf:datatype"] = @datatype.full_uri
58
+ end
48
59
  opts["xml:lang"] = @lang if @lang
49
60
  block.call(@obj.to_s, opts)
50
61
  end
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module IqRdf
16
- VERSION = "0.1.4"
16
+ VERSION = "0.1.5"
17
17
  end
data/test/turtle_test.rb CHANGED
@@ -137,6 +137,7 @@ rdf
137
137
  t.married(false)
138
138
  t.weight(65.8)
139
139
  t.complex(IqRdf::Literal.new("A very complex type", :none, URI.parse("http://this.com/is#complex")))
140
+ t.complex2(IqRdf::Literal.new("Shorter form", :none, IqRdf::myDatatype))
140
141
  t.quotes("\"I'm \\quoted\"")
141
142
  t.line_breaks("I'm written\nover two lines")
142
143
  t.some_literal(IqRdf::Literal.new("text", :de))
@@ -155,6 +156,7 @@ rdf
155
156
  :married false;
156
157
  :weight 65.8;
157
158
  :complex "A very complex type"^^<http://this.com/is#complex>;
159
+ :complex2 "Shorter form"^^:myDatatype;
158
160
  :quotes "\\"I'm \\\\quoted\\""@de;
159
161
  :line_breaks """I'm written
160
162
  over two lines"""@de;
data/test/xml_test.rb CHANGED
@@ -179,6 +179,7 @@ skos:testnode :test32 [
179
179
  t.married(false)
180
180
  t.weight(65.8)
181
181
  t.complex(IqRdf::Literal.new("A very complex type", :none, URI.parse("http://this.com/is#complex")))
182
+ t.complex2(IqRdf::Literal.new("Shorter form", :none, IqRdf::myDatatype))
182
183
  t.quotes("\"I'm \\quoted\"")
183
184
  t.line_breaks("I'm written\nover two lines")
184
185
  t.some_literal(IqRdf::Literal.new("text", :de))
@@ -195,6 +196,7 @@ skos:testnode :test32 [
195
196
  <married rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</married>
196
197
  <weight rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">65.8</weight>
197
198
  <complex rdf:datatype="http://this.com/is#complex" xml:lang="none">A very complex type</complex>
199
+ <complex2 rdf:datatype="http://www.test.de/myDatatype" xml:lang="none">Shorter form</complex2>
198
200
  <quotes>"I'm \\quoted"</quotes>
199
201
  <line_breaks>I'm written
200
202
  over two lines</line_breaks>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iq_rdf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Till Schulte-Coerne