redlander 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,25 @@
1
1
  require "spec_helper"
2
-
3
- require 'date'
2
+ require "date"
4
3
 
5
4
  describe Node do
5
+ before { @options = {} }
6
6
 
7
7
  describe "blank" do
8
- subject { Node.new }
8
+ subject { described_class.new(nil, @options) }
9
9
 
10
10
  it { should be_blank }
11
11
 
12
12
  it "should have a blank identifier for a blank node" do
13
13
  subject.value.should match(/^_:\w+$/)
14
14
  end
15
+
16
+ context "when given :blank_id" do
17
+ before { @options = {:blank_id => "blank0"} }
18
+
19
+ it "should create a node with the given identifier" do
20
+ expect(subject.value).to eql "_:blank0"
21
+ end
22
+ end
15
23
  end
16
24
 
17
25
  it "should create a resource node" do
@@ -19,46 +27,53 @@ describe Node do
19
27
  Node.new(resource_uri).should be_resource
20
28
  end
21
29
 
30
+ it "should create a literal node from a literal rdf_node" do
31
+ node1 = Node.new("hello, world")
32
+ node2 = Node.new(node1.rdf_node)
33
+ node2.datatype.should_not be_nil
34
+ node2.datatype.should eql node1.datatype
35
+ end
36
+
22
37
  it "should create a string literal" do
23
38
  node = Node.new("hello, world")
24
39
  node.should be_literal
25
- node.datatype.should eql("http://www.w3.org/2001/XMLSchema#string")
40
+ node.datatype.should eql URI("http://www.w3.org/2001/XMLSchema#string")
26
41
  end
27
42
 
28
43
  it "should create a boolean literal" do
29
44
  node = Node.new(true)
30
45
  node.should be_literal
31
- node.datatype.should eql("http://www.w3.org/2001/XMLSchema#boolean")
46
+ node.datatype.should eql URI("http://www.w3.org/2001/XMLSchema#boolean")
32
47
  end
33
48
 
34
49
  it "should create an integer number literal" do
35
50
  node = Node.new(10)
36
51
  node.should be_literal
37
- node.datatype.should eql("http://www.w3.org/2001/XMLSchema#int")
52
+ node.datatype.should eql URI("http://www.w3.org/2001/XMLSchema#int")
38
53
  end
39
54
 
40
55
  it "should create a floating-point number literal" do
41
56
  node = Node.new(3.1416)
42
57
  node.should be_literal
43
- node.datatype.should eql("http://www.w3.org/2001/XMLSchema#float")
58
+ node.datatype.should eql URI("http://www.w3.org/2001/XMLSchema#float")
44
59
  end
45
60
 
46
61
  it "should create a time literal" do
47
62
  node = Node.new(Time.now)
48
63
  node.should be_literal
49
- node.datatype.should eql("http://www.w3.org/2001/XMLSchema#time")
64
+ node.datatype.should eql URI("http://www.w3.org/2001/XMLSchema#time")
50
65
  end
51
66
 
52
67
  it "should create a date literal" do
53
68
  node = Node.new(Date.today)
54
69
  node.should be_literal
55
- node.datatype.should eql("http://www.w3.org/2001/XMLSchema#date")
70
+ node.datatype.should eql URI("http://www.w3.org/2001/XMLSchema#date")
56
71
  end
57
72
 
58
73
  it "should create a datetime literal" do
59
74
  node = Node.new(DateTime.now)
60
75
  node.should be_literal
61
- node.datatype.should eql("http://www.w3.org/2001/XMLSchema#dateTime")
76
+ node.datatype.should eql URI("http://www.w3.org/2001/XMLSchema#dateTime")
62
77
  end
63
78
 
64
79
  it "should have proper string representation" do
@@ -75,8 +90,7 @@ describe Node do
75
90
  end
76
91
 
77
92
  it "should have an instance of URI for a resource node" do
78
- resource_uri = URI.parse('http://example.com/nodes#node_1')
93
+ resource_uri = URI('http://example.com/nodes#node_1')
79
94
  Node.new(resource_uri).value.should be_an_instance_of(URI::HTTP)
80
95
  end
81
-
82
96
  end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe Statement do
4
+ subject { described_class.new(statement_attributes) }
5
+
6
+ context "with default values" do
7
+ subject { described_class.new }
8
+
9
+ it "should have nil subject" do
10
+ subject.subject.should be_nil
11
+ end
12
+
13
+ it "should have nil predicate" do
14
+ subject.predicate.should be_nil
15
+ end
16
+
17
+ it "should have nil object" do
18
+ subject.object.should be_nil
19
+ end
20
+
21
+ [:subject, :predicate, :object].each do |attribute|
22
+ it "should be assigned a #{attribute}" do
23
+ attr = Node.new(statement_attributes[attribute])
24
+ expect {
25
+ subject.send("#{attribute}=", attr)
26
+ }.to change(subject, attribute).from(nil).to(attr)
27
+ end
28
+ end
29
+ end
30
+
31
+ it "should be created with the given values" do
32
+ subject.subject.should be_an_instance_of(Node)
33
+ subject.predicate.should be_an_instance_of(Node)
34
+ subject.object.should be_an_instance_of(Node)
35
+ end
36
+
37
+ it "should have proper attributes" do
38
+ subject.subject.value.to_s.should eql('http://example.com/concepts#subject')
39
+ subject.predicate.value.to_s.should eql('http://example.com/concepts#label')
40
+ subject.object.value.should eql('subject!')
41
+ end
42
+
43
+
44
+ private
45
+
46
+ def statement_attributes
47
+ s = URI.parse('http://example.com/concepts#subject')
48
+ p = URI.parse('http://example.com/concepts#label')
49
+ o = "subject!"
50
+ {
51
+ :subject => s,
52
+ :predicate => p,
53
+ :object => o
54
+ }
55
+ end
56
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,18 @@
1
- require 'spec/autorun'
2
-
3
- require 'lib/redlander'
1
+ require 'redlander'
4
2
  include Redlander
5
3
 
6
- Spec::Runner.configure do |config|
4
+ # Helpful testing methods
5
+ Redlander.module_eval <<HERE
6
+ class << self
7
+ def root
8
+ '#{File.expand_path(File.join(File.dirname(__FILE__), ".."))}'
9
+ end
10
+
11
+ def fixture_path(filename = "")
12
+ File.join(root, "spec", "fixtures", filename)
13
+ end
14
+ end
15
+ HERE
16
+
17
+ RSpec.configure do |config|
7
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redlander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: xml_schema
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.0.1
21
+ version: 0.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.0.1
29
+ version: 0.1.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: ffi
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '1.0'
37
+ version: '1.1'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '1.0'
45
+ version: '1.1'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '1'
53
+ version: '2'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,43 +58,52 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '1'
62
- description: ! ' Advanced Redland bindings.
61
+ version: '2'
62
+ description: ! 'Redlander is Ruby bindings to Redland library (see http://librdf.org)
63
+ written in C, which is used to manipulate RDF graphs. This is an alternative implementation
64
+ of Ruby bindings (as opposed to the official bindings), aiming to be more intuitive,
65
+ lightweight, high-performing and as bug-free as possible.
63
66
 
64
67
  '
65
- email: slava.kravchenko@gmail.com
68
+ email:
69
+ - slava.kravchenko@gmail.com
66
70
  executables: []
67
71
  extensions: []
68
72
  extra_rdoc_files:
69
73
  - README.rdoc
74
+ - ChangeLog
70
75
  files:
76
+ - .gitignore
77
+ - ChangeLog
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE
81
+ - README.rdoc
82
+ - Rakefile
71
83
  - lib/redland.rb
72
- - lib/redlander/error_container.rb
73
- - lib/redlander/model_proxy.rb
74
- - lib/redlander/parser.rb
75
- - lib/redlander/parser_proxy.rb
76
- - lib/redlander/serializer.rb
77
- - lib/redlander/storage.rb
78
- - lib/redlander/stream.rb
79
- - lib/redlander/stream_enumerator.rb
80
- - lib/redlander/version.rb
81
- - lib/redlander/uri.rb
84
+ - lib/redlander.rb
82
85
  - lib/redlander/exceptions.rb
83
86
  - lib/redlander/model.rb
87
+ - lib/redlander/model_proxy.rb
84
88
  - lib/redlander/node.rb
89
+ - lib/redlander/parsing.rb
90
+ - lib/redlander/serializing.rb
85
91
  - lib/redlander/statement.rb
86
- - lib/redlander.rb
92
+ - lib/redlander/uri.rb
93
+ - lib/redlander/version.rb
94
+ - redlander.gemspec
95
+ - spec/fixtures/doap.nt
96
+ - spec/fixtures/doap.rdf
97
+ - spec/fixtures/doap.ttl
87
98
  - spec/integration/memory_leak_spec.rb
88
- - spec/redlander/model_spec.rb
89
- - spec/redlander/parser_spec.rb
90
- - spec/redlander/serializer_spec.rb
91
- - spec/redlander/statement_spec.rb
92
- - spec/redlander/node_spec.rb
99
+ - spec/lib/redlander/model_spec.rb
100
+ - spec/lib/redlander/node_spec.rb
101
+ - spec/lib/redlander/statement_spec.rb
102
+ - spec/spec.opts
93
103
  - spec/spec_helper.rb
94
- - Rakefile
95
- - README.rdoc
96
104
  homepage: https://github.com/cordawyn/redlander
97
- licenses: []
105
+ licenses:
106
+ - The MIT License (MIT)
98
107
  post_install_message:
99
108
  rdoc_options: []
100
109
  require_paths:
@@ -107,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
116
  version: '0'
108
117
  segments:
109
118
  - 0
110
- hash: -3193927855587243710
119
+ hash: 3614393653179496496
111
120
  required_rubygems_version: !ruby/object:Gem::Requirement
112
121
  none: false
113
122
  requirements:
@@ -116,17 +125,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
125
  version: '0'
117
126
  segments:
118
127
  - 0
119
- hash: -3193927855587243710
128
+ hash: 3614393653179496496
120
129
  requirements: []
121
130
  rubyforge_project:
122
131
  rubygems_version: 1.8.24
123
132
  signing_key:
124
133
  specification_version: 3
125
- summary: Advanced Redland bindings.
134
+ summary: Advanced Ruby bindings for Redland runtime library (librdf).
126
135
  test_files:
136
+ - spec/fixtures/doap.nt
137
+ - spec/fixtures/doap.rdf
138
+ - spec/fixtures/doap.ttl
127
139
  - spec/integration/memory_leak_spec.rb
128
- - spec/redlander/model_spec.rb
129
- - spec/redlander/parser_spec.rb
130
- - spec/redlander/serializer_spec.rb
131
- - spec/redlander/statement_spec.rb
132
- - spec/redlander/node_spec.rb
140
+ - spec/lib/redlander/model_spec.rb
141
+ - spec/lib/redlander/node_spec.rb
142
+ - spec/lib/redlander/statement_spec.rb
143
+ - spec/spec.opts
144
+ - spec/spec_helper.rb
@@ -1,42 +0,0 @@
1
- module Redlander
2
- module ErrorContainer
3
- class Errors
4
- include Enumerable
5
-
6
- def initialize
7
- @container = []
8
- end
9
-
10
- def add(error_message)
11
- if @container.include?(error_message)
12
- @container
13
- else
14
- @container << error_message
15
- end
16
- end
17
-
18
- def each
19
- @container.each do |err|
20
- yield err
21
- end
22
- end
23
-
24
- def empty?
25
- @container.empty?
26
- end
27
-
28
- def clear
29
- @container.clear
30
- end
31
-
32
- def size
33
- @container.size
34
- end
35
- end
36
-
37
- def errors
38
- @errors ||= Errors.new
39
- end
40
-
41
- end
42
- end
@@ -1,92 +0,0 @@
1
- require 'redlander/parser_proxy'
2
-
3
- module Redlander
4
- class Parser
5
- attr_reader :rdf_parser
6
-
7
- # Create a new parser.
8
- # Name can be either of [:rdfxml, :ntriples, :turtle],
9
- # or nil, which defaults to :rdfxml.
10
- #
11
- # TODO: Only a small subset of parsers is implemented,
12
- # because the rest seem to be very buggy.
13
- def initialize(name = :rdfxml)
14
- # name, mime-type and syntax uri can all be nil, which defaults to :rdfxml parser
15
- @rdf_parser = Redland.librdf_new_parser(Redlander.rdf_world, name.to_s, nil, nil)
16
- raise RedlandError.new("Failed to create a new parser") if @rdf_parser.null?
17
- ObjectSpace.define_finalizer(self, proc { Redland.librdf_free_parser(@rdf_parser) })
18
- end
19
-
20
- # Parse the content (String) into the model.
21
- #
22
- # Options are:
23
- # :base_uri base URI (String or URI)
24
- #
25
- # Returns true on success, or false.
26
- def from_string(model, content, options = {})
27
- # FIXME: A bug (?) in Redland breaks NTriples parser if its input is not terminated with "\n"
28
- content.concat("\n") unless content.end_with?("\n")
29
- base_uri = if options.has_key?(:base_uri)
30
- Uri.new(options[:base_uri]).rdf_uri
31
- else
32
- nil
33
- end
34
- Redland.librdf_parser_parse_string_into_model(@rdf_parser, content, base_uri, model.rdf_model).zero?
35
- end
36
-
37
- # Parse the content from URI into the model.
38
- # (It is possible to use "file:" schema for local files).
39
- #
40
- # Options are:
41
- # :base_uri base URI (String or URI)
42
- #
43
- # Returns true on success, or false.
44
- def from_uri(model, uri, options = {})
45
- uri = URI.parse(uri)
46
- uri = URI.parse("file://#{File.expand_path(uri.to_s)}") if uri.scheme.nil?
47
- base_uri = if options.has_key?(:base_uri)
48
- Uri.new(options[:base_uri]).rdf_uri
49
- else
50
- nil
51
- end
52
- Redland.librdf_parser_parse_into_model(@rdf_parser, Uri.new(uri).rdf_uri, base_uri, model.rdf_model).zero?
53
- end
54
- alias_method :from_file, :from_uri
55
-
56
- def statements(content, options = {})
57
- # FIXME: A bug (?) in Redland breaks NTriples parser if its input is not terminated with "\n"
58
- content.concat("\n") unless content.end_with?("\n")
59
- ParserProxy.new(self, content, options)
60
- end
61
- end
62
-
63
- # Applied to Model
64
- module ParsingInstanceMethods
65
- def from_rdfxml(content, options = {})
66
- parser = Parser.new(:rdfxml)
67
- parser.from_string(self, content, options)
68
- end
69
-
70
- def from_ntriples(content, options = {})
71
- parser = Parser.new(:ntriples)
72
- parser.from_string(self, content, options)
73
- end
74
-
75
- def from_turtle(content, options = {})
76
- parser = Parser.new(:turtle)
77
- parser.from_string(self, content, options)
78
- end
79
-
80
- # Load the model from an URI content.
81
- #
82
- # Options are:
83
- # :format - content format [:rdfxml (default), :ntriples, :turtle]
84
- # :base_uri - base URI
85
- def from_uri(uri, options = {})
86
- parser_options = options.dup
87
- parser = Parser.new(parser_options.delete(:format) || :rdfxml)
88
- parser.from_uri(self, uri, parser_options)
89
- end
90
- alias_method :from_file, :from_uri
91
- end
92
- end