Skip to content

Commit 26dad57

Browse files
committed
Make language option explicit for overriding the default language.
1 parent 7aead53 commit 26dad57

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/json/ld/api.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class API
7171
# A context that is used to initialize the active context when expanding a document.
7272
# @option options [Boolean, String, RDF::URI] :flatten
7373
# If set to a value that is not `false`, the JSON-LD processor must modify the output of the Compaction Algorithm or the Expansion Algorithm by coalescing all properties associated with each subject via the Flattening Algorithm. The value of `flatten must` be either an _IRI_ value representing the name of the graph to flatten, or `true`. If the value is `true`, then the first graph encountered in the input document is selected and flattened.
74+
# @option options [String] :language
75+
# When set, this has the effect of inserting a context definition with `@language` set to the associated value, creating a default language for interpreting string values.
7476
# @option options [String] :processingMode
7577
# Processing mode, json-ld-1.0 or json-ld-1.1.
7678
# If `processingMode` is not specified, a mode of `json-ld-1.0` or `json-ld-1.1` is set, the context used for `expansion` or `compaction`.
@@ -84,6 +86,7 @@ class API
8486
# @yieldparam [API]
8587
# @raise [JsonLdError]
8688
def initialize(input, context, rename_bnodes: true, unique_bnodes: false, **options, &block)
89+
#require 'byebug'; byebug
8790
@options = {
8891
compactArrays: true,
8992
documentLoader: self.class.method(:documentLoader)

spec/expand_spec.rb

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,32 @@
9696
it(title) {run_expand params}
9797
end
9898

99+
context "default language" do
100+
{
101+
"base": {
102+
input: %({
103+
"http://example/foo": "bar"
104+
}),
105+
output: %([{
106+
"http://example/foo": [{"@value": "bar", "@language": "en"}]
107+
}]),
108+
language: "en"
109+
},
110+
"override": {
111+
input: %({
112+
"@context": {"@language": null},
113+
"http://example/foo": "bar"
114+
}),
115+
output: %([{
116+
"http://example/foo": [{"@value": "bar"}]
117+
}]),
118+
language: "en"
119+
}
120+
}.each_pair do |title, params|
121+
it(title) {run_expand params}
122+
end
123+
end
124+
99125
context "with relative IRIs" do
100126
{
101127
"base": {
@@ -2349,14 +2375,14 @@
23492375
end
23502376

23512377
def run_expand(params)
2352-
input, output, processingMode = params[:input], params[:output], params[:processingMode]
2378+
input, output = params[:input], params[:output]
23532379
input = ::JSON.parse(input) if input.is_a?(String)
23542380
output = ::JSON.parse(output) if output.is_a?(String)
23552381
pending params.fetch(:pending, "test implementation") unless input
23562382
if params[:exception]
2357-
expect {JSON::LD::API.expand(input, {processingMode: processingMode}.merge(params))}.to raise_error(params[:exception])
2383+
expect {JSON::LD::API.expand(input, params)}.to raise_error(params[:exception])
23582384
else
2359-
jld = JSON::LD::API.expand(input, base: params[:base], logger: logger, processingMode: processingMode)
2385+
jld = JSON::LD::API.expand(input, {logger: logger}.merge(params))
23602386
expect(jld).to produce(output, logger)
23612387
end
23622388
end

0 commit comments

Comments
 (0)