Module: RoadForest::Testing::HelperMethods
- Included in:
- BeEquivalentGraph
- Defined in:
- lib/roadforest/test-support/matchers.rb
Instance Method Summary collapse
-
#detect_format(stream) ⇒ Object
Heuristically detect the input stream.
- #normalize(graph) ⇒ Object
- #statements_from_graph(graph) ⇒ Object
Instance Method Details
#detect_format(stream) ⇒ Object
Heuristically detect the input stream
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/roadforest/test-support/matchers.rb', line 21 def detect_format(stream) # Got to look into the file to see if stream.is_a?(IO) || stream.is_a?(StringIO) stream.rewind string = stream.read(1000) stream.rewind else string = stream.to_s end case string when /<html/i then RDF::RDFa::Reader when /@prefix/i then RDF::Turtle::Reader else RDF::NTriples::Reader end end |
#normalize(graph) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/roadforest/test-support/matchers.rb', line 37 def normalize(graph) case graph when RDF::Queryable then graph when IO, StringIO RDF::Graph.new.load(graph, :base_uri => @info.about) else # Figure out which parser to use g = RDF::Graph.new reader_class = detect_format(graph) reader_class.new(graph, :base_uri => @info.nil? ? nil : @info.about).each {|s| g << s} g end end |
#statements_from_graph(graph) ⇒ Object
16 17 18 |
# File 'lib/roadforest/test-support/matchers.rb', line 16 def statements_from_graph(graph) StatementsFromGraph.new(graph) end |