lib/json/ld/compact.rb in json-ld-0.1.2 vs lib/json/ld/compact.rb in json-ld-0.1.3

- old
+ new

@@ -5,11 +5,10 @@ ## # Compact an expanded Array or Hash given an active property and a context. # # @param [Array, Hash] element # @param [String] property (nil) - # @param [EvaluationContext] context # @return [Array, Hash] def compact(element, property = nil) if property.nil? debug("compact") {"element: #{element.inspect}, ec: #{context.inspect}"} else @@ -66,10 +65,11 @@ element.each do |key, value| debug("compact") {"#{key}: #{value.inspect}"} if %(@id @type).include?(key) compacted_key = context.compact_iri(key, :position => :predicate, :depth => @depth) + result[compacted_key] = case value when String # If value is a string, the compacted value is the result of performing IRI Compaction on value. debug {" => compacted string for #{key}"} context.compact_iri(value, :position => :subject, :depth => @depth) @@ -82,17 +82,19 @@ end else if value.empty? # Make sure that an empty array is preserved compacted_key = context.compact_iri(key, :position => :predicate, :depth => @depth) + next if compacted_key.nil? result[compacted_key] = value end # For each item in value: raise ProcessingError, "found #{value.inspect} for #{key} if #{element.inspect}" unless value.is_a?(Array) value.each do |item| compacted_key = context.compact_iri(key, :position => :predicate, :value => item, :depth => @depth) debug {" => compacted key: #{compacted_key.inspect} for #{item.inspect}"} + next if compacted_key.nil? compacted_item = depth {self.compact(item, compacted_key)} debug {" => compacted value: #{compacted_value.inspect}"} case result[compacted_key]