class

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)
Source

Instance methods

add_arg(value : String) : Nil

Adds the provided value to the internal args array.

Source
add_forced_array(name : String) : Nil
Source
add_xml_namespace(prefix : String, href : String) : Nil
Source
indent

The number of spaces to use for indentation.

Source
indent=(indent : Int32)

The number of spaces to use for indentation.

Source
input_format

The format that the input data is in.

Source
input_format=(input_format : Format)

The format that the input data is in.

Source
null=(null : Bool)

Do not read any input, using null as the singular input value.

Source
null?

Do not read any input, using null as the singular input value.

Source
output_format

The format that the output should be transcoded into.

Source
output_format=(output_format : Format)

The format that the output should be transcoded into.

Source
process(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.

Source
tab

DEPRECATED Use Processor#tab? instead.

Source
tab=(tab : Bool)

If a tab for each indentation level instead of spaces.

Source
tab?

If a tab for each indentation level instead of spaces.

Source
xml_item

The name for XML array elements without keys.

Source
xml_item=(xml_item : String)

The name for XML array elements without keys.

Source
xml_prolog

DEPRECATED Use Processor#xml_prolog? instead.

Source
xml_prolog=(xml_prolog : Bool)

If the XML prolog should be emitted.

Source
xml_prolog?

If the XML prolog should be emitted.

Source
xml_root

The root of the XML document when transcoding to XML.

Source
xml_root=(xml_root : String)

The root of the XML document when transcoding to XML.

Source
xmlns=(xmlns : Bool)

If XML namespaces should be parsed as well. TODO: Remove this in oq 2.0 as it'll becomethe default.

Source
xmlns?

If XML namespaces should be parsed as well. TODO: Remove this in oq 2.0 as it'll becomethe default.

Source