Skip to content

Commit ac1f6b0

Browse files
committed
Add support for lists for framing.
1 parent 220931f commit ac1f6b0

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/json/ld/frame.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def frame(state, subjects, frame, **options)
126126

127127
case
128128
when list?(o)
129+
subframe = frame[prop].first['@list'] if Array(frame[prop]).first.is_a?(Hash)
130+
subframe ||= create_implicit_frame(flags)
129131
# add empty list
130132
list = {'@list' => []}
131133
add_frame_output(output, prop, list)
@@ -319,6 +321,23 @@ def filter_subject(subject, frame, state, flags)
319321
node_values.any? do |nv|
320322
node_match?(v, nv, state, flags)
321323
end
324+
elsif list?(v)
325+
vv = v['@list'].first
326+
node_values = list?(node_values.first) ?
327+
node_values.first['@list'] :
328+
false
329+
if !node_values
330+
false # Lists match Lists
331+
elsif value?(vv)
332+
# Match on any matching value
333+
node_values.any? {|nv| value_match?(vv, nv)}
334+
elsif node?(vv) || node_reference?(vv)
335+
node_values.any? do |nv|
336+
node_match?(vv, nv, state, flags)
337+
end
338+
else
339+
false
340+
end
322341
else
323342
false # No matching on non-value or node values
324343
end

spec/frame_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,41 @@
508508
}]
509509
})
510510
},
511+
"framed list" => {
512+
frame: %({
513+
"@context": {
514+
"ex": "http://example.org/",
515+
"list": {"@id": "ex:list", "@container": "@list"}
516+
},
517+
"list": [{"@type": "ex:Element"}]
518+
}),
519+
input: %({
520+
"@context": {
521+
"ex": "http://example.org/",
522+
"list": {"@id": "ex:list", "@container": "@list"}
523+
},
524+
"@id": "ex:Sub1",
525+
"@type": "ex:Type1",
526+
"list": [
527+
{"@id": "ex:Sub2", "@type": "ex:Element"},
528+
"literal1"
529+
]
530+
}),
531+
output: %({
532+
"@context": {
533+
"ex": "http://example.org/",
534+
"list": {"@id": "ex:list", "@container": "@list"}
535+
},
536+
"@graph": [{
537+
"@id": "ex:Sub1",
538+
"@type": "ex:Type1",
539+
"list": [
540+
{"@id": "ex:Sub2", "@type": "ex:Element"},
541+
"literal1"
542+
]
543+
}]
544+
})
545+
},
511546
"presentation example" => {
512547
frame: %({
513548
"@context": {

0 commit comments

Comments
 (0)