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.e. 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.
- #add_forced_array(name : String) : Nil
- #add_xml_namespace(prefix : String, href : String) : Nil
-
#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.
-
#null=(null : Bool)
Do not read any input, using
null
as the singular input value. -
#null? : Bool
Do not read any input, using
null
as the singular input value. -
#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
DEPRECATED Use
Processor#tab?
instead. -
#tab=(tab : Bool)
If a tab for each indentation level instead of spaces.
-
#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
DEPRECATED Use
Processor#xml_prolog?
instead. -
#xml_prolog=(xml_prolog : Bool)
If the XML prolog should be emitted.
-
#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.
-
#xmlns=(xmlns : Bool)
If XML namespaces should be parsed as well.
-
#xmlns? : Bool
If XML namespaces should be parsed as well.
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
.
If XML namespaces should be parsed as well.
TODO Remove this in oq 2.0 as it'll becomethe default.
If XML namespaces should be parsed as well.
TODO Remove this in oq 2.0 as it'll becomethe default.