lib/json/ld/api.rb in json-ld-2.1.5 vs lib/json/ld/api.rb in json-ld-2.1.6

- old
+ new

@@ -172,11 +172,11 @@ result = self.expand(self.value, nil, self.context, ordered: options.fetch(:ordered, true)) doc_base = @options[:base] end # If, after the algorithm outlined above is run, the resulting element is an JSON object with just a @graph property, element is set to the value of @graph's value. - result = result['@graph'] if result.is_a?(Hash) && result.keys == %w(@graph) + result = result['@graph'] if result.is_a?(Hash) && result.length == 1 && result.key?('@graph') # Finally, if element is a JSON object, it is wrapped into an array. result = [result].compact unless result.is_a?(Array) if block_given? @@ -275,10 +275,12 @@ # Initialize node map to a JSON object consisting of a single member whose key is @default and whose value is an empty JSON object. graph_maps = {'@default' => {}} create_node_map(value, graph_maps) default_graph = graph_maps['@default'] - graph_maps.keys.kw_sort.reject {|k| k == '@default'}.each do |graph_name| + graph_maps.keys.kw_sort.each do |graph_name| + next if graph_name == '@default' + graph = graph_maps[graph_name] entry = default_graph[graph_name] ||= {'@id' => graph_name} nodes = entry['@graph'] ||= [] graph.keys.kw_sort.each do |id| nodes << graph[id] unless node_reference?(graph[id])