lib/json/ld/api.rb in json-ld-2.1.1 vs lib/json/ld/api.rb in json-ld-2.1.2
- old
+ new
@@ -58,12 +58,11 @@
# @param [String, #read, Hash, Array] input
# @param [String, #read, Hash, Array, JSON::LD::Context] context
# An external context to use additionally to the context embedded in input when expanding the input.
# @param [Hash{Symbol => Object}] options
# @option options [String, #to_s] :base
- # The Base IRI to use when expanding the document. This overrides the value of `input` if it is a _IRI_. If not specified and `input` is not an _IRI_, the base IRI defaults to the current document IRI if in a browser context, or the empty string if there is no document context.
- # If not specified, and a base IRI is found from `input`, options[:base] will be modified with this value.
+ # The Base IRI to use when expanding the document. This overrides the value of `input` if it is a _IRI_. If not specified and `input` is not an _IRI_, the base IRI defaults to the current document IRI if in a browser context, or the empty string if there is no document context. If not specified, and a base IRI is found from `input`, options[:base] will be modified with this value.
# @option options [Boolean] :compactArrays (true)
# If set to `true`, the JSON-LD processor replaces arrays with just one element with that element during compaction. If set to `false`, all arrays will remain arrays even if they have just one element.
# @option options [Proc] :documentLoader
# The callback of the loader to be used to retrieve remote documents and contexts. If specified, it must be used to retrieve remote documents and contexts; otherwise, if not specified, the processor's built-in loader must be used. See {documentLoader} for the method signature.
# @option options [String, #read, Hash, Array, JSON::LD::Context] :expandContext
@@ -146,12 +145,11 @@
# This is used internally only
private :initialize
##
- # Expands the given input according to the steps in the Expansion Algorithm. The input must be copied, expanded and returned
- # if there are no errors. If the expansion fails, an appropriate exception must be thrown.
+ # Expands the given input according to the steps in the Expansion Algorithm. The input must be copied, expanded and returned if there are no errors. If the expansion fails, an appropriate exception must be thrown.
#
# The resulting `Array` either returned or yielded
#
# @param [String, #read, Hash, Array] input
# The JSON-LD object to copy and perform the expansion upon.
@@ -169,22 +167,20 @@
result = nil
API.new(input, options[:expandContext], options) do |api|
result = api.expand(api.value, nil, api.context, ordered: options.fetch(:ordered, true))
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.
+ # 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)
# Finally, if element is a JSON object, it is wrapped into an array.
result = [result].compact unless result.is_a?(Array)
block_given? ? yield(result) : result
end
##
- # Compacts the given input according to the steps in the Compaction Algorithm. The input must be copied, compacted and
- # returned if there are no errors. If the compaction fails, an appropirate exception must be thrown.
+ # Compacts the given input according to the steps in the Compaction Algorithm. The input must be copied, compacted and returned if there are no errors. If the compaction fails, an appropirate exception must be thrown.
#
# If no context is provided, the input document is compacted using the top-level context of the document
#
# The resulting `Hash` is either returned or yielded, if a block is given.
#
@@ -282,33 +278,26 @@
block_given? ? yield(flattened) : flattened
end
##
- # Frames the given input using the frame according to the steps in the Framing Algorithm. The input is used to build the
- # framed output and is returned if there are no errors. If there are no matches for the frame, null must be returned.
- # Exceptions must be thrown if there are errors.
+ # Frames the given input using the frame according to the steps in the Framing Algorithm. The input is used to build the framed output and is returned if there are no errors. If there are no matches for the frame, null must be returned. Exceptions must be thrown if there are errors.
#
# The resulting `Array` is either returned, or yielded if a block is given.
#
# @param [String, #read, Hash, Array] input
# The JSON-LD object to copy and perform the framing on.
# @param [String, #read, Hash, Array] frame
# The frame to use when re-arranging the data.
# @option options (see #initialize)
# @option options ['@last', '@always', '@never', '@link'] :embed ('@last')
- # a flag specifying that objects should be directly embedded in the output,
- # instead of being referred to by their IRI.
+ # a flag specifying that objects should be directly embedded in the output, instead of being referred to by their IRI.
# @option options [Boolean] :explicit (false)
- # a flag specifying that for properties to be included in the output,
- # they must be explicitly declared in the framing context.
+ # a flag specifying that for properties to be included in the output, they must be explicitly declared in the framing context.
# @option options [Boolean] :requireAll (true)
- # A flag specifying that all properties present in the input frame must
- # either have a default value or be present in the JSON-LD input for the
- # frame to match.
+ # A flag specifying that all properties present in the input frame must either have a default value or be present in the JSON-LD input for the frame to match.
# @option options [Boolean] :omitDefault (false)
- # a flag specifying that properties that are missing from the JSON-LD
- # input should be omitted from the output.
+ # a flag specifying that properties that are missing from the JSON-LD input should be omitted from the output.
# @option options [Boolean] :expanded Input is already expanded
# @yield jsonld
# @yieldparam [Hash] jsonld
# The framed JSON-LD document
# @yieldreturn [Object] returned object