Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

.to_sym and #to_sym for Format, Reader and Writer, to retrieve a symb…

…ol appropriate for use with .for().
  • Loading branch information...
commit 5a6dbcdb01afc131b3ce70fee69711b42c0233e0 1 parent ca95691
@gkellogg gkellogg authored
View
10 lib/rdf/format.rb
@@ -140,6 +140,16 @@ def self.file_extensions
end
##
+ # Returns a symbol appropriate to use with RDF::Format.for()
+ # @return [Symbol]
+ def self.to_sym
+ elements = self.to_s.split("::")
+ sym = elements.pop
+ sym = elements.pop if sym == 'Format'
+ sym.downcase.to_s.to_sym
+ end
+
+ ##
# Retrieves or defines the reader class for this RDF serialization
# format.
#
View
17 lib/rdf/reader.rb
@@ -128,6 +128,23 @@ def self.open(filename, options = {}, &block)
end
##
+ # Returns a symbol appropriate to use with RDF::Reader.for()
+ # @return [Symbol]
+ def self.to_sym
+ elements = self.to_s.split("::")
+ sym = elements.pop
+ sym = elements.pop if sym == 'Reader'
+ sym.downcase.to_s.to_sym
+ end
+
+ ##
+ # Returns a symbol appropriate to use with RDF::Reader.for()
+ # @return [Symbol]
+ def to_sym
+ self.class.to_sym
+ end
+
+ ##
# Initializes the reader.
#
# @param [IO, File, String] input
View
17 lib/rdf/writer.rb
@@ -159,6 +159,23 @@ def self.open(filename, options = {}, &block)
end
##
+ # Returns a symbol appropriate to use with RDF::Writer.for()
+ # @return [Symbol]
+ def self.to_sym
+ elements = self.to_s.split("::")
+ sym = elements.pop
+ sym = elements.pop if sym == 'Writer'
+ sym.downcase.to_s.to_sym
+ end
+
+ ##
+ # Returns a symbol appropriate to use with RDF::Writer.for()
+ # @return [Symbol]
+ def to_sym
+ self.class.to_sym
+ end
+
+ ##
# Initializes the writer.
#
# @param [IO, File] output
View
14 spec/nquads_spec.rb
@@ -23,6 +23,10 @@
]
formats.each { |format| format.should == RDF::NQuads::Format }
end
+
+ it "should return :nquads for to_sym" do
+ RDF::NQuads::Format.to_sym.should == :nquads
+ end
end
describe RDF::NQuads::Reader do
@@ -34,7 +38,6 @@
# @see lib/rdf/spec/reader.rb in rdf-spec
it_should_behave_like RDF_Reader
-
it "should be discoverable" do
readers = [
RDF::Reader.for(:nquads),
@@ -45,6 +48,11 @@
]
readers.each { |reader| reader.should == RDF::NQuads::Reader }
end
+
+ it "should return :nquads for to_sym" do
+ @reader.class.to_sym.should == :nquads
+ @reader.to_sym.should == :nquads
+ end
end
describe RDF::NQuads::Writer do
@@ -60,4 +68,8 @@
]
writers.each { |writer| writer.should == RDF::NQuads::Writer }
end
+
+ it "should return :nquads for to_sym" do
+ RDF::NQuads::Writer.to_sym.should == :nquads
+ end
end
View
13 spec/ntriples_spec.rb
@@ -22,6 +22,10 @@
]
formats.each { |format| format.should == RDF::NTriples::Format }
end
+
+ it "should return :ntriples for to_sym" do
+ RDF::NTriples::Format.to_sym.should == :ntriples
+ end
end
describe RDF::NTriples::Reader do
@@ -42,6 +46,11 @@
]
readers.each { |reader| reader.should == RDF::NTriples::Reader }
end
+
+ it "should return :ntriples for to_sym" do
+ @reader.class.to_sym.should == :ntriples
+ @reader.to_sym.should == :ntriples
+ end
end
describe RDF::NTriples::Writer do
@@ -55,6 +64,10 @@
]
writers.each { |writer| writer.should == RDF::NTriples::Writer }
end
+
+ it "should return :ntriples for to_sym" do
+ RDF::NTriples::Writer.to_sym.should == :ntriples
+ end
end
describe RDF::NTriples do
Please sign in to comment.
Something went wrong with that request. Please try again.