class OQ::Processor
- OQ::Processor
- Reference
- Object
Overview
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.g. the filter and/or any other arguments that should be passed to `jq`.
processor.process ["."], input: input_io, output: file
end
Defined in:
oq.crConstructors
Instance Method Summary
-
#add_arg(value : String) : Nil
Adds the provided value to the internal args array.
-
#indent : Int32
The number of spaces to use for indentation.
-
#indent=(indent : Int32)
The number of spaces to use for indentation.
-
#input_format : Format
The format that the input data is in.
-
#input_format=(input_format : Format)
The format that the input data is in.
-
#output_format : Format
The format that the output should be transcoded into.
-
#output_format=(output_format : Format)
The format that the output should be transcoded into.
-
#process(input_args : Array(String) = ARGV, input : IO = ARGF, output : IO = STDOUT, error : IO = STDERR) : Nil
Consumes
#input_format
data from the provided inputIO
, along with any input_args. -
#tab : Bool
If a tab for each indentation level instead of spaces.
-
#tab=(tab : Bool)
If a tab for each indentation level instead of spaces.
-
#xml_item : String
The name for XML array elements without keys.
-
#xml_item=(xml_item : String)
The name for XML array elements without keys.
-
#xml_prolog : Bool
If the XML prolog should be emitted.
-
#xml_prolog=(xml_prolog : Bool)
If the XML prolog should be emitted.
-
#xml_root : String
The root of the XML document when transcoding to XML.
-
#xml_root=(xml_root : String)
The root of the XML document when transcoding to XML.
Constructor Detail
Instance Method Detail
The format that the output should be transcoded into.
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
.