Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…ol appropriate for use with .for(). (cherry-picking from commit 5a6dbcd)
  • Loading branch information...
commit 8bb0f571e6b588ef94fbfe81a86a22dd1f15bd2e 1 parent c0156b1
Gregg Kellogg gkellogg authored
10 lib/rdf/format.rb
View
@@ -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.
#
17 lib/rdf/reader.rb
View
@@ -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
17 lib/rdf/writer.rb
View
@@ -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
14 spec/nquads_spec.rb
View
@@ -24,6 +24,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
@@ -35,7 +39,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),
@@ -46,6 +49,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
@@ -68,4 +76,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
13 spec/ntriples_spec.rb
View
@@ -23,6 +23,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
@@ -43,6 +47,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
@@ -63,6 +72,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.