@@ -299,10 +299,10 @@ def compact(element,
299299 else
300300 index_key = context . expand_iri ( index_key , vocab : true )
301301 container_key = context . compact_iri ( index_key , vocab : true )
302- map_key , *others = Array ( compacted_item [ container_key ] )
302+ map_key , *others = Array ( compacted_item . is_a? ( Hash ) && compacted_item [ container_key ] )
303303 if map_key . is_a? ( String )
304304 case others . length
305- when 0 then compacted_item . delete ( container_key )
305+ when 0 then compacted_item . delete ( container_key ) if compacted_item . is_a? ( Hash )
306306 when 1 then compacted_item [ container_key ] = others . first
307307 else compacted_item [ container_key ] = others
308308 end
@@ -316,15 +316,15 @@ def compact(element,
316316 map_key = expanded_item [ '@language' ]
317317 value? ( expanded_item ) ? expanded_item [ '@value' ] : compacted_item
318318 elsif container . include? ( '@type' )
319- map_key , *types = Array ( compacted_item [ container_key ] )
319+ map_key , *types = Array ( compacted_item . is_a? ( Hash ) && compacted_item [ container_key ] )
320320 case types . length
321- when 0 then compacted_item . delete ( container_key )
321+ when 0 then compacted_item . delete ( container_key ) if compacted_item . is_a? ( Hash )
322322 when 1 then compacted_item [ container_key ] = types . first
323323 else compacted_item [ container_key ] = types
324324 end
325325
326326 # if compacted_item contains a single entry who's key maps to @id, then recompact the item without @type
327- if compacted_item . keys . length == 1 && expanded_item . key? ( '@id' )
327+ if compacted_item . is_a? ( Hash ) && compacted_item . keys . length == 1 && expanded_item . key? ( '@id' )
328328 compacted_item = compact ( { '@id' => expanded_item [ '@id' ] } ,
329329 base : base ,
330330 property : item_active_property ,
0 commit comments