module RoadForest::Testing::HelperMethods
Public Instance Methods
detect_format(stream)
click to toggle source
Heuristically detect the input stream
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 16 def statements_from_graph(graph) StatementsFromGraph.new(graph) end