amigo 0.1.3 → 0.1.4

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.
@@ -1,3 +1,11 @@
1
+ === 0.1.4 / 2010-05-31
2
+
3
+ * Implement Solution#to_ary so you can auto-expand the variables as block arguments.
4
+
5
+ * Improve error message when solution variable not found.
6
+
7
+ * Implement Store#to_ntriples.
8
+
1
9
  === 0.1.3 / 2010-05-23
2
10
 
3
11
  * Fixed: weird 1.9 scoping behaviour.
@@ -17,7 +17,11 @@ module Amigo
17
17
 
18
18
  def [](name)
19
19
  return @row[name] if include?(name)
20
- raise NameError, "#{name} not found"
20
+ raise NameError, "#{name.inspect} not found"
21
+ end
22
+
23
+ def to_ary
24
+ @variables.map(@row).to_ary
21
25
  end
22
26
 
23
27
  def eql?(other)
@@ -26,6 +26,10 @@ module Amigo
26
26
  query.execute(@triples)
27
27
  end
28
28
 
29
+ def to_ntriples
30
+ @triples.map(&:to_ntriple).join("\n")
31
+ end
32
+
29
33
  def eql?(other)
30
34
  return true if other.equal?(self)
31
35
  other.class.equal?(self.class) &&
@@ -36,6 +36,10 @@ module Amigo
36
36
  @names.include?(name)
37
37
  end
38
38
 
39
+ def map(row)
40
+ @names.map { |name| row[name] }
41
+ end
42
+
39
43
  def to_sparql
40
44
  @names.map { |name| "?#{name}" }.join(" ")
41
45
  end
@@ -1,5 +1,5 @@
1
1
  module Amigo
2
2
 
3
- VERSION = "0.1.3".freeze
3
+ VERSION = "0.1.4".freeze
4
4
 
5
5
  end
@@ -9,14 +9,14 @@ module Amigo
9
9
  describe "#to_sql" do
10
10
 
11
11
  [
12
- [Select.new(:*), "SELECT * FROM triples LIMIT 0"],
13
- [Select.new(:*).where(:x, :y, :z), "SELECT subject x, predicate y, object z FROM triples"],
14
- [Select.new(:x, :y, :z).where(:x, :y, :z), "SELECT subject x, predicate y, object z FROM triples"],
15
- [Select.new(:x, :z).where(:x, :y, :z), "SELECT subject x, object z FROM triples"],
16
- [Select.new(:*).where(:x, "bee", :z), "SELECT subject x, object z, FROM triples WHERE triples.predicate = 'bee'"],
17
- [Select.new(:x, :z).where(:x, "bee", :z), "SELECT subject x, object z FROM triples WHERE triples.predicate = 'bee'"],
18
- [Select.new(:*).where(:x, "bee", :z).where("dee", :y, "eff"), "SELECT a.subject x, a.object z, b.predicate y FROM triples a CROSS JOIN triples b WHERE a.predicate = 'bee' AND b.subject = 'dee' AND b.object = 'eff'"],
19
- [Select.new(:x, :y).where(:x, "bee", :z).where(:z, :y, "see"), "SELECT a.subject x, b.predicate y FROM triples a JOIN triples b ON (a.object = b.subject) WHERE a.predicate = 'bee' AND b.object = 'see'"],
12
+ [Select.new(:*), "SELECT * FROM triple LIMIT 0"],
13
+ [Select.new(:*).where(:x, :y, :z), "SELECT subject x, predicate y, object z FROM triple"],
14
+ [Select.new(:x, :y, :z).where(:x, :y, :z), "SELECT subject x, predicate y, object z FROM triple"],
15
+ [Select.new(:x, :z).where(:x, :y, :z), "SELECT subject x, object z FROM triple"],
16
+ [Select.new(:*).where(:x, "bee", :z), "SELECT subject x, object z, FROM triple WHERE triple.predicate = 'bee'"],
17
+ [Select.new(:x, :z).where(:x, "bee", :z), "SELECT subject x, object z FROM triple WHERE triple.predicate = 'bee'"],
18
+ [Select.new(:*).where(:x, "bee", :z).where("dee", :y, "eff"), "SELECT a.subject x, a.object z, b.predicate y FROM triple a CROSS JOIN triple b WHERE a.predicate = 'bee' AND b.subject = 'dee' AND b.object = 'eff'"],
19
+ [Select.new(:x, :y).where(:x, "bee", :z).where(:z, :y, "see"), "SELECT a.subject x, b.predicate y FROM triple a JOIN triple b ON (a.object = b.subject) WHERE a.predicate = 'bee' AND b.object = 'see'"],
20
20
  ].each do |select, sql|
21
21
 
22
22
  describe "given #{select.inspect}" do
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ require 'hamster/list'
4
+ require 'hamster/hash'
5
+ require 'amigo/solution'
6
+
7
+ module Amigo
8
+
9
+ describe Solution do
10
+
11
+ describe "#to_ary" do
12
+
13
+ before do
14
+ @solution = Solution.new(
15
+ Hamster.list(:a, :b, :c),
16
+ Hamster.hash(:a => "Aye", :b => "Bee", :c => "See")
17
+ ).to_ary
18
+ end
19
+
20
+ it "should description" do
21
+ @solution.to_ary.should == ["Aye", "Bee", "See"]
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
+ require 'amigo/uri'
3
4
  require 'amigo/store'
4
5
 
5
6
  module Amigo
@@ -8,7 +9,18 @@ module Amigo
8
9
 
9
10
  describe "#to_ntriples" do
10
11
 
11
-
12
+ before do
13
+ @store = Store.new.
14
+ add("a", "b", "c").
15
+ add(URI.parse("http://www.example.com/x"), "b", URI.parse("http://www.example.com/z"))
16
+ end
17
+
18
+ it "returns a textual representation of the store in the form of N-Triples" do
19
+ [
20
+ %Q{"a" "b" "c" .\n<http://www.example.com/x> "b" <http://www.example.com/z> .},
21
+ %Q{<http://www.example.com/x> "b" <http://www.example.com/z> .\n"a" "b" "c" .}
22
+ ].should include(@store.to_ntriples)
23
+ end
12
24
 
13
25
  end
14
26
 
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ require 'amigo/uri'
4
+ require 'amigo/store'
5
+
6
+ module Amigo
7
+
8
+ describe Store do
9
+
10
+ describe "#to_sql" do
11
+
12
+ before do
13
+ @store = Store.new.
14
+ add("a", "b", "c").
15
+ add(URI.parse("http://www.example.com/x"), "b", URI.parse("http://www.example.com/z"))
16
+ end
17
+
18
+ it "returns a textual representation of the store in the form of SQL" do
19
+ # COPY triple (subject, predicate, object) FROM stdin;
20
+ # \.
21
+ # ].should include(@store.to_ntriples)
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amigo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Harris
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-23 00:00:00 +10:00
18
+ date: 2010-05-31 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -97,8 +97,10 @@ files:
97
97
  - spec/amigo/select/immutable_spec.rb
98
98
  - spec/amigo/select/to_sparql_spec.rb
99
99
  - spec/amigo/select/to_sql_spec.rb
100
+ - spec/amigo/solution/to_ary_spec.rb
100
101
  - spec/amigo/store/hash_spec.rb
101
102
  - spec/amigo/store/to_ntriples_spec.rb
103
+ - spec/amigo/store/to_sql_spec.rb
102
104
  - spec/amigo/term/to_sparql_spec.rb
103
105
  - spec/amigo/triple/immutable_spec.rb
104
106
  - spec/amigo/triple/inspect_spec.rb