iq_rdf 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -174,4 +174,4 @@
174
174
  incurred by, or claims asserted against, such Contributor by reason
175
175
  of your accepting any such warranty or additional liability.
176
176
 
177
- END OF TERMS AND CONDITIONS
177
+ END OF TERMS AND CONDITIONS
data/README.md CHANGED
@@ -26,10 +26,10 @@ document = IqRdf::Document.new('http://www.test.de/')
26
26
  document.namespaces :skos => 'http://www.w3.org/2008/05/skos#',
27
27
  :foaf => 'http://xmlns.com/foaf/0.1/' # A :rdf namespace is added automatically
28
28
 
29
- document << IqRdf::john_doe.myCustomNote("This is an example", :lang => :en)
29
+ document << IqRdf::john_doe.myCustomNote("This is an example", :lang => :en)
30
30
  # Turtle: :john_doe :myCustomNote "This is an example"@en.
31
31
 
32
- document << IqRdf::john_doe(IqRdf::Foaf::build_uri("Person")).Foaf::name("John Doe")
32
+ document << IqRdf::john_doe(IqRdf::Foaf::build_uri("Person")).Foaf::name("John Doe")
33
33
  # Turtle: :john_doe a foaf:Person; foaf:name "John Doe".
34
34
 
35
35
  document << IqRdf::john_doe.Foaf::knows(IqRdf::jane_doe)
@@ -46,7 +46,7 @@ Gemfile (or with Rails 2.x in your config/environment.rb):
46
46
  ```ruby
47
47
  gem "iq_rdf"
48
48
  ```
49
-
49
+
50
50
  Add the mime types you want to support to your config/initializers/mime_types.rb
51
51
  file:
52
52
 
@@ -55,7 +55,7 @@ Mime::Type.register "application/rdf+xml", :rdf
55
55
  Mime::Type.register "text/turtle", :ttl
56
56
  Mime::Type.register "application/n-triples", :nt
57
57
  ```
58
-
58
+
59
59
  Now you can define views in you application. Use the extension *.iqrdf*
60
60
  for the view files. You can use the extensions *.ttl* or
61
61
  *.rdf* in the URL of your request, to force the output to be
data/iq_rdf.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.summary = "IqRdf - A builder like rdf library for ruby and rails"
27
27
  s.description = s.summary
28
28
  s.extra_rdoc_files = ['README.md', 'LICENSE']
29
-
29
+
30
30
  s.add_dependency "bundler"
31
31
  s.add_dependency "builder"
32
32
 
@@ -23,7 +23,7 @@ module IqRdf
23
23
  end
24
24
 
25
25
  def to_turtle(parent_lang = nil)
26
-
26
+
27
27
  end
28
28
 
29
29
  def to_s(parent_lang = nil)
@@ -20,7 +20,7 @@ module IqRdf
20
20
  def initialize(collection)
21
21
  @elements = []
22
22
  collection.each do |element|
23
- element = Literal.new(element) unless element.is_a?(IqRdf::Uri)
23
+ element = Literal.new(element) unless element.is_a?(IqRdf::Uri) || element.is_a?(IqRdf::Literal)
24
24
  @elements << element
25
25
  end
26
26
  end
@@ -90,4 +90,4 @@ module IqRdf
90
90
  end
91
91
 
92
92
  end
93
- end
93
+ end
@@ -0,0 +1,15 @@
1
+ module IqRdf
2
+ class Literal
3
+ class Boolean < Literal
4
+
5
+ def initialize(b)
6
+ super(!!b, nil, ::URI.parse("http://www.w3.org/2001/XMLSchema#boolean"))
7
+ end
8
+
9
+ def to_s(parent_lang = nil)
10
+ @obj.to_s
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module IqRdf
2
+ class Literal
3
+ class Numeric < Literal
4
+
5
+ def initialize(num)
6
+ raise "#{num.inspect} is not a Numeric!" unless num.is_a?(::Numeric)
7
+ super(num, nil, ::URI.parse(num.is_a?(Integer) ? "http://www.w3.org/2001/XMLSchema#integer" : "http://www.w3.org/2001/XMLSchema#decimal"))
8
+ end
9
+
10
+ def to_s(parent_lang = nil)
11
+ @obj.to_s
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module IqRdf
2
+ class Literal
3
+ class String < Literal
4
+
5
+ def initialize(s, lang = nil)
6
+ raise "#{s.inspect} is not a String" unless s.is_a?(::String)
7
+ super(s, lang)
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module IqRdf
2
+ class Literal
3
+ class URI < Literal
4
+
5
+ def initialize(uri)
6
+ raise "#{uri.inspect} is not an URI" unless uri.is_a?(::URI)
7
+ super(uri)
8
+ end
9
+
10
+ def to_s(parent_lang = nil)
11
+ "<#{@obj.to_s}>"
12
+ end
13
+
14
+ def build_xml(xml, &block)
15
+ block.call("rdf:resource" => @obj.to_s)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -15,42 +15,38 @@
15
15
  module IqRdf
16
16
  class Literal
17
17
 
18
- def initialize(obj, lang = nil)
18
+ def initialize(obj, lang = nil, datatype = nil)
19
+ raise "#{datatype.inspect} is not an URI" if datatype && !datatype.is_a?(::URI)
19
20
  @obj = obj
21
+ @datatype = datatype
20
22
  @lang = lang
21
23
  end
22
24
 
23
- def to_s(lang = nil)
24
- lang = @lang || lang # Use the Literals lang when given
25
- if @obj.is_a?(URI)
26
- "<#{@obj.to_s}>"
27
- elsif @obj === true
28
- "true"
29
- elsif @obj === false
30
- "false"
31
- elsif @obj.is_a?(Numeric)
32
- @obj.to_s
25
+ def self.build(o)
26
+ if o.is_a?(::URI)
27
+ IqRdf::Literal::URI.new(o)
28
+ elsif o === true || o === false
29
+ IqRdf::Literal::Boolean.new(o)
30
+ elsif o.is_a?(::Numeric)
31
+ IqRdf::Literal::Numeric.new(o)
33
32
  else
34
- quote = @obj.to_s.include?("\n") ? '"""' : '"'
35
- "#{quote}#{@obj.to_s.gsub("\\", "\\\\\\\\").gsub(/"/, "\\\"")}#{quote}#{(lang && lang != :none) ? "@#{lang}" : ""}"
33
+ IqRdf::Literal::String.new(o)
36
34
  end
37
35
  end
38
36
 
37
+ def to_s(parent_lang = nil)
38
+ lang = @lang || parent_lang # Use the Literals lang when given
39
+ quote = @obj.to_s.include?("\n") ? '"""' : '"'
40
+ "#{quote}#{@obj.to_s.gsub("\\", "\\\\\\\\").gsub(/"/, "\\\"")}#{quote}" <<
41
+ ((lang && lang != :none) ? "@#{lang}" : "") <<
42
+ (@datatype ? "^^<#{@datatype.to_s}>" : "")
43
+ end
44
+
39
45
  def build_xml(xml, &block)
40
- if @obj.is_a?(URI)
41
- block.call("rdf:resource" => @obj.to_s)
42
- else
43
- opts = {}
44
- { Integer => "http://www.w3.org/2001/XMLSchema#integer",
45
- Float => "http://www.w3.org/2001/XMLSchema#decimal",
46
- TrueClass => "http://www.w3.org/2001/XMLSchema#boolean",
47
- FalseClass => "http://www.w3.org/2001/XMLSchema#boolean",
48
- }.each do |klass, s|
49
- opts["rdf:datatype"] = s if @obj.is_a?(klass)
50
- end
51
- opts["xml:lang"] = @lang if @lang
52
- block.call(@obj.to_s, opts)
53
- end
46
+ opts = {}
47
+ opts["rdf:datatype"] = @datatype.to_s if @datatype
48
+ opts["xml:lang"] = @lang if @lang
49
+ block.call(@obj.to_s, opts)
54
50
  end
55
51
 
56
52
  alias_method :full_uri, :to_s
@@ -38,7 +38,7 @@ module IqRdf
38
38
  end
39
39
 
40
40
  # Namespace only methods
41
-
41
+
42
42
  def self.create(token, uri_prefix)
43
43
  klass_name = self.class_name(token)
44
44
  klass = IqRdf.const_defined?(klass_name) ? IqRdf.const_get(klass_name) : IqRdf.const_set(klass_name, Class.new(self))
@@ -66,6 +66,6 @@ module IqRdf
66
66
  def self.class_name(name)
67
67
  name.to_s.gsub(/(^|_)(.)/) { $2.upcase }
68
68
  end
69
-
69
+
70
70
  end
71
- end
71
+ end
@@ -27,4 +27,4 @@ module IqRdf
27
27
  alias_method :full_uri, :to_s
28
28
 
29
29
  end
30
- end
30
+ end
@@ -44,7 +44,7 @@ module IqRdf
44
44
  o = IqRdf::Default.build_uri(o)
45
45
  else
46
46
  return nil if options[:suppress_if_empty] === true && (o.nil? || o === "")
47
- o = Literal.new(o)
47
+ o = Literal.build(o)
48
48
  end
49
49
  predicate << o
50
50
  end
@@ -38,6 +38,6 @@ module ActionView
38
38
  EOV
39
39
  end
40
40
  end
41
-
41
+
42
42
  end
43
43
  end
data/lib/iq_rdf/uri.rb CHANGED
@@ -66,4 +66,4 @@ module IqRdf
66
66
  end
67
67
 
68
68
  end
69
- end
69
+ end
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module IqRdf
16
- VERSION = "0.1.2"
16
+ VERSION = "0.1.3"
17
17
  end
data/lib/iq_rdf.rb CHANGED
@@ -18,6 +18,10 @@ require 'iq_rdf/blank_node'
18
18
  require 'iq_rdf/predicate'
19
19
 
20
20
  require 'iq_rdf/literal'
21
+ require 'iq_rdf/literal/boolean'
22
+ require 'iq_rdf/literal/string'
23
+ require 'iq_rdf/literal/uri'
24
+ require 'iq_rdf/literal/numeric'
21
25
  require 'iq_rdf/plain_turtle_literal'
22
26
  require 'iq_rdf/namespace'
23
27
  require 'iq_rdf/collection'
@@ -75,4 +79,4 @@ module IqRdf
75
79
  Namespace.dummy_empty_namespace.build_uri(uri, type, &block)
76
80
  end
77
81
 
78
- end
82
+ end
data/test/turtle_test.rb CHANGED
@@ -17,7 +17,7 @@ $LOAD_PATH << File.dirname(__FILE__)
17
17
  require 'test_helper'
18
18
 
19
19
  class TurtleTest < Test::Unit::TestCase
20
-
20
+
21
21
  def test_basic_turtle_output
22
22
  document = IqRdf::Document.new('http://www.test.de/', :lang => :de)
23
23
  document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
@@ -136,6 +136,7 @@ rdf
136
136
  t.age(32)
137
137
  t.married(false)
138
138
  t.weight(65.8)
139
+ t.complex(IqRdf::Literal.new("A very complex type", :none, URI.parse("http://this.com/is#complex")))
139
140
  t.quotes("\"I'm \\quoted\"")
140
141
  t.line_breaks("I'm written\nover two lines")
141
142
  t.some_literal(IqRdf::Literal.new("text", :de))
@@ -153,6 +154,7 @@ rdf
153
154
  :age 32;
154
155
  :married false;
155
156
  :weight 65.8;
157
+ :complex "A very complex type"^^<http://this.com/is#complex>;
156
158
  :quotes "\\"I'm \\\\quoted\\""@de;
157
159
  :line_breaks """I'm written
158
160
  over two lines"""@de;
@@ -213,5 +215,5 @@ rdf
213
215
  ].
214
216
  rdf
215
217
  end
216
-
217
- end
218
+
219
+ end
data/test/xml_test.rb CHANGED
@@ -17,7 +17,7 @@ $LOAD_PATH << File.dirname(__FILE__)
17
17
  require 'test_helper'
18
18
 
19
19
  class XmlTest < Test::Unit::TestCase
20
-
20
+
21
21
  def test_basic_xml_output
22
22
  document = IqRdf::Document.new('http://www.test.de/', :lang => :de)
23
23
  document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
@@ -68,7 +68,7 @@ rdf
68
68
  document.namespaces :skos => 'http://www.w3.org/2008/05/skos#', :foaf => 'http://xmlns.com/foaf/0.1/', :upb => 'http://www.upb.de/'
69
69
 
70
70
  document << IqRdf::testemann.myCustomNote("This is an example", :lang => :en) # :testemann :myCustomNote "This is an example"@en.
71
-
71
+
72
72
  document << IqRdf::testemann(IqRdf::Foaf::build_uri("Person")).Foaf::name("Heinz Peter Testemann", :lang => :none) # :testemann a foaf:Person; foaf:name "Heinz Peter Testemann" .
73
73
  document << IqRdf::testemann.Foaf::knows(IqRdf::testefrau) # :testemann foaf:knows :testefrau .
74
74
  document << IqRdf::testemann.Foaf::nick("Crash test dummy") # :testemann foaf:nick "Crash test dummy"@de .
@@ -178,6 +178,7 @@ skos:testnode :test32 [
178
178
  t.age(32)
179
179
  t.married(false)
180
180
  t.weight(65.8)
181
+ t.complex(IqRdf::Literal.new("A very complex type", :none, URI.parse("http://this.com/is#complex")))
181
182
  t.quotes("\"I'm \\quoted\"")
182
183
  t.line_breaks("I'm written\nover two lines")
183
184
  t.some_literal(IqRdf::Literal.new("text", :de))
@@ -193,6 +194,7 @@ skos:testnode :test32 [
193
194
  <age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">32</age>
194
195
  <married rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</married>
195
196
  <weight rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">65.8</weight>
197
+ <complex rdf:datatype="http://this.com/is#complex" xml:lang="none">A very complex type</complex>
196
198
  <quotes>"I'm \\quoted"</quotes>
197
199
  <line_breaks>I'm written
198
200
  over two lines</line_breaks>
@@ -232,4 +234,4 @@ rdf
232
234
  rdf
233
235
  end
234
236
 
235
- end
237
+ end
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: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Till Schulte-Coerne
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-25 00:00:00 Z
18
+ date: 2012-02-22 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false
@@ -63,6 +63,10 @@ files:
63
63
  - lib/iq_rdf/blank_node.rb
64
64
  - lib/iq_rdf/collection.rb
65
65
  - lib/iq_rdf/document.rb
66
+ - lib/iq_rdf/literal/boolean.rb
67
+ - lib/iq_rdf/literal/numeric.rb
68
+ - lib/iq_rdf/literal/string.rb
69
+ - lib/iq_rdf/literal/uri.rb
66
70
  - lib/iq_rdf/literal.rb
67
71
  - lib/iq_rdf/namespace.rb
68
72
  - lib/iq_rdf/node.rb