Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

.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
Gregg Kellogg gkellogg authored
10 lib/rdf/format.rb
@@ -140,6 +140,16 @@ def self.file_extensions
140 140 end
141 141
142 142 ##
  143 + # Returns a symbol appropriate to use with RDF::Format.for()
  144 + # @return [Symbol]
  145 + def self.to_sym
  146 + elements = self.to_s.split("::")
  147 + sym = elements.pop
  148 + sym = elements.pop if sym == 'Format'
  149 + sym.downcase.to_s.to_sym
  150 + end
  151 +
  152 + ##
143 153 # Retrieves or defines the reader class for this RDF serialization
144 154 # format.
145 155 #
17 lib/rdf/reader.rb
@@ -128,6 +128,23 @@ def self.open(filename, options = {}, &block)
128 128 end
129 129
130 130 ##
  131 + # Returns a symbol appropriate to use with RDF::Reader.for()
  132 + # @return [Symbol]
  133 + def self.to_sym
  134 + elements = self.to_s.split("::")
  135 + sym = elements.pop
  136 + sym = elements.pop if sym == 'Reader'
  137 + sym.downcase.to_s.to_sym
  138 + end
  139 +
  140 + ##
  141 + # Returns a symbol appropriate to use with RDF::Reader.for()
  142 + # @return [Symbol]
  143 + def to_sym
  144 + self.class.to_sym
  145 + end
  146 +
  147 + ##
131 148 # Initializes the reader.
132 149 #
133 150 # @param [IO, File, String] input
17 lib/rdf/writer.rb
@@ -159,6 +159,23 @@ def self.open(filename, options = {}, &block)
159 159 end
160 160
161 161 ##
  162 + # Returns a symbol appropriate to use with RDF::Writer.for()
  163 + # @return [Symbol]
  164 + def self.to_sym
  165 + elements = self.to_s.split("::")
  166 + sym = elements.pop
  167 + sym = elements.pop if sym == 'Writer'
  168 + sym.downcase.to_s.to_sym
  169 + end
  170 +
  171 + ##
  172 + # Returns a symbol appropriate to use with RDF::Writer.for()
  173 + # @return [Symbol]
  174 + def to_sym
  175 + self.class.to_sym
  176 + end
  177 +
  178 + ##
162 179 # Initializes the writer.
163 180 #
164 181 # @param [IO, File] output
14 spec/nquads_spec.rb
@@ -23,6 +23,10 @@
23 23 ]
24 24 formats.each { |format| format.should == RDF::NQuads::Format }
25 25 end
  26 +
  27 + it "should return :nquads for to_sym" do
  28 + RDF::NQuads::Format.to_sym.should == :nquads
  29 + end
26 30 end
27 31
28 32 describe RDF::NQuads::Reader do
@@ -34,7 +38,6 @@
34 38 # @see lib/rdf/spec/reader.rb in rdf-spec
35 39 it_should_behave_like RDF_Reader
36 40
37   -
38 41 it "should be discoverable" do
39 42 readers = [
40 43 RDF::Reader.for(:nquads),
@@ -45,6 +48,11 @@
45 48 ]
46 49 readers.each { |reader| reader.should == RDF::NQuads::Reader }
47 50 end
  51 +
  52 + it "should return :nquads for to_sym" do
  53 + @reader.class.to_sym.should == :nquads
  54 + @reader.to_sym.should == :nquads
  55 + end
48 56 end
49 57
50 58 describe RDF::NQuads::Writer do
@@ -60,4 +68,8 @@
60 68 ]
61 69 writers.each { |writer| writer.should == RDF::NQuads::Writer }
62 70 end
  71 +
  72 + it "should return :nquads for to_sym" do
  73 + RDF::NQuads::Writer.to_sym.should == :nquads
  74 + end
63 75 end
13 spec/ntriples_spec.rb
@@ -22,6 +22,10 @@
22 22 ]
23 23 formats.each { |format| format.should == RDF::NTriples::Format }
24 24 end
  25 +
  26 + it "should return :ntriples for to_sym" do
  27 + RDF::NTriples::Format.to_sym.should == :ntriples
  28 + end
25 29 end
26 30
27 31 describe RDF::NTriples::Reader do
@@ -42,6 +46,11 @@
42 46 ]
43 47 readers.each { |reader| reader.should == RDF::NTriples::Reader }
44 48 end
  49 +
  50 + it "should return :ntriples for to_sym" do
  51 + @reader.class.to_sym.should == :ntriples
  52 + @reader.to_sym.should == :ntriples
  53 + end
45 54 end
46 55
47 56 describe RDF::NTriples::Writer do
@@ -55,6 +64,10 @@
55 64 ]
56 65 writers.each { |writer| writer.should == RDF::NTriples::Writer }
57 66 end
  67 +
  68 + it "should return :ntriples for to_sym" do
  69 + RDF::NTriples::Writer.to_sym.should == :ntriples
  70 + end
58 71 end
59 72
60 73 describe RDF::NTriples do

0 comments on commit 5a6dbcd

Please sign in to comment.
Something went wrong with that request. Please try again.