Skip to content

Commit 31b034a

Browse files
committed
Finish 1.1.3.1. Implement callback mode of Reader#each_triple.
2 parents 4ce38e0 + 810154b commit 31b034a

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.3
1+
1.1.3.1

etc/doap.nt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<http://rubygems.org/gems/json-ld> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://usefulinc.com/ns/doap#Project> .
2+
<http://rubygems.org/gems/json-ld> <http://purl.org/dc/terms/creator> <http://greggkellogg.net/foaf#me> .
3+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#blog> <http://greggkellogg.net/> .
4+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#bug-database> <http://github.com/ruby-rdf/json-ld/issues> .
5+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#created> "2011-05-07"^^<http://www.w3.org/2001/XMLSchema#date> .
6+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#description> "RDF.rb extension for parsing/serializing JSON-LD data."@en .
7+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#developer> <http://greggkellogg.net/foaf#me> .
8+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#documenter> <http://greggkellogg.net/foaf#me> .
9+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#homepage> <http://github.com/ruby-rdf/json-ld/> .
10+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#implements> <http://json-ld.org/spec/latest/json-ld-api/> .
11+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#implements> <http://json-ld.org/spec/latest/json-ld-syntax/> .
12+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#license> <http://creativecommons.org/licenses/publicdomain/> .
13+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#maintainer> <http://greggkellogg.net/foaf#me> .
14+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#name> "JSON::LD" .
15+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#platform> "Ruby" .
16+
<http://rubygems.org/gems/json-ld> <http://usefulinc.com/ns/doap#shortdesc> "JSON-LD support for RDF.rb."@en .
17+
<http://rubygems.org/gems/json-ld> <http://xmlns.com/foaf/0.1/maker> <http://greggkellogg.net/foaf#me> .
18+
<http://greggkellogg.net/foaf#me> <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <http://greggkellogg.net/foaf> .
19+
<http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/made> <http://rubygems.org/gems/json-ld> .
20+
<http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/mbox> <mailto:gregg@greggkellogg.net> .
21+
<http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/name> "Gregg Kellogg" .

lib/json/ld/reader.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ def each_statement(&block)
5858
##
5959
# @private
6060
# @see RDF::Reader#each_triple
61-
def each_triple
62-
JSON::LD::API.toRdf(@doc, @options) do |statement|
63-
yield *statement.to_triple
61+
def each_triple(&block)
62+
if block_given?
63+
JSON::LD::API.toRdf(@doc, @options) do |statement|
64+
yield *statement.to_triple
65+
end
6466
end
67+
enum_for(:each_triple)
6568
end
6669
end
6770
end

spec/reader_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
require 'rdf/spec/reader'
55

66
describe JSON::LD::Reader do
7+
let!(:doap) {File.expand_path("../../etc/doap.jsonld", __FILE__)}
8+
let!(:doap_nt) {File.expand_path("../../etc/doap.nt", __FILE__)}
9+
let!(:doap_count) {File.open(doap_nt).each_line.to_a.length}
10+
11+
before(:each) do
12+
@reader_input = File.read(doap)
13+
@reader = JSON::LD::Reader.new(@reader_input)
14+
@reader_count = doap_count
15+
end
716
before :each do
817
@reader = JSON::LD::Reader.new(StringIO.new(""))
918
end

0 commit comments

Comments
 (0)