OQ::Processor
Inherits Reference / Object
Handles the logic of converting the input format (if needed), processing it via jq, and converting the output format (if needed).
require "oq"
# This could be any `IO`, e.g. an `HTTP` request body, etc.
input_io = IO::Memory.new %({"name":"Jim"})
# Create a processor, specifying that we want the output format to be `YAML`.
processor = OQ::Processor.new output_format: :yaml
File.open("./out.yml", "w") do |file|
# Process the data using our custom input and output IOs.
# The first argument represents the input arguments;
# i.e. the filter and/or any other arguments that should be passed to `jq`.
processor.process ["."], input: input_io, output: file
end
Constructors
new(input_format : Format = Format::JSON, output_format : Format = Format::JSON, xml_root : String = "root", xml_prolog : Bool = true, xml_item : String = "item", indent : Int32 = 2, tab : Bool = false, null : Bool = false, xmlns : Bool = false)
SourceInstance methods
add_forced_array(name : String) : Nil
Sourceadd_xml_namespace(prefix : String, href : String) : Nil
Sourceprocess(input_args : Array(String) = ARGV, input : IO = ARGF, output : IO = STDOUT, error : IO = STDERR) : Nil
Consumes #input_format data from the provided input IO, along with any input_args.
The data is then converted to JSON, passed to jq, and then converted to #output_format while being written to the output IO.
Any errors are written to the error IO.
xmlns=(xmlns : Bool)
If XML namespaces should be parsed as well. TODO: Remove this in oq 2.0 as it'll becomethe default.
xmlns?
If XML namespaces should be parsed as well. TODO: Remove this in oq 2.0 as it'll becomethe default.