lib/json/ld/api.rb in json-ld-1.0.7 vs lib/json/ld/api.rb in json-ld-1.0.8
- old
+ new
@@ -361,35 +361,35 @@
# If true, output will include statements having blank node predicates, otherwise they are dropped.
# @raise [JsonLdError]
# @return [Array<RDF::Statement>] if no block given
# @yield statement
# @yieldparam [RDF::Statement] statement
- def self.toRDF(input, options = {}, &block)
+ def self.toRdf(input, options = {}, &block)
results = []
results.extend(RDF::Enumerable)
# Expand input to simplify processing
expanded_input = API.expand(input, options)
API.new(expanded_input, nil, options) do
# 1) Perform the Expansion Algorithm on the JSON-LD input.
# This removes any existing context to allow the given context to be cleanly applied.
- debug(".toRDF") {"expanded input: #{expanded_input.to_json(JSON_STATE)}"}
+ debug(".toRdf") {"expanded input: #{expanded_input.to_json(JSON_STATE)}"}
# Generate _nodeMap_
node_map = Hash.ordered
node_map['@default'] = Hash.ordered
generate_node_map(expanded_input, node_map)
- debug(".toRDF") {"node map: #{node_map.to_json(JSON_STATE)}"}
+ debug(".toRdf") {"node map: #{node_map.to_json(JSON_STATE)}"}
# Start generating statements
node_map.each do |graph_name, graph|
context = as_resource(graph_name) unless graph_name == '@default'
- debug(".toRDF") {"context: #{context ? context.to_ntriples : 'null'}"}
+ debug(".toRdf") {"context: #{context ? context.to_ntriples : 'null'}"}
# Drop results for graphs which are named with relative IRIs
if graph_name.is_a?(RDF::URI) && !graph_name.absolute
- debug(".toRDF") {"drop relative graph_name: #{statement.to_ntriples}"}
+ debug(".toRdf") {"drop relative graph_name: #{statement.to_ntriples}"}
next
end
graph_to_rdf(graph).each do |statement|
next if statement.predicate.node? && !options[:produceGeneralizedRdf]
# Drop results with relative IRIs
@@ -402,11 +402,11 @@
else
false
end
end
if relative
- debug(".toRDF") {"drop statement with relative IRIs: #{statement.to_ntriples}"}
+ debug(".toRdf") {"drop statement with relative IRIs: #{statement.to_ntriples}"}
next
end
statement.context = context if context
if block_given?
@@ -431,11 +431,11 @@
# @yield jsonld
# @yieldparam [Hash] jsonld
# The JSON-LD document in expanded form
# @return [Array<Hash>]
# The JSON-LD document in expanded form
- def self.fromRDF(input, options = {}, &block)
+ def self.fromRdf(input, options = {}, &block)
options = {:useNativeTypes => false}.merge(options)
result = nil
API.new(nil, nil, options) do |api|
result = api.from_statements(input)
@@ -522,9 +522,15 @@
end
return block_given? ? yield(remote_document) : remote_document
end
end
+ end
+
+ # Add class method aliases for backwards compatibility
+ class << self
+ alias :toRDF :toRdf
+ alias :fromRDF :fromRdf
end
##
# A {RemoteDocument} is returned from a {documentLoader}.
class RemoteDocument