class OQ::Processor

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.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) #

[View source]

Instance Method Detail

def add_arg(value : String) : Nil #

Adds the provided value to the internal args array.


[View source]
def add_forced_array(name : String) : Nil #

[View source]
def add_xml_namespace(prefix : String, href : String) : Nil #

[View source]
def indent : Int32 #

The number of spaces to use for indentation.


[View source]
def indent=(indent : Int32) #

The number of spaces to use for indentation.


[View source]
def input_format : Format #

The format that the input data is in.


[View source]
def input_format=(input_format : Format) #

The format that the input data is in.


[View source]
def null=(null : Bool) #

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


[View source]
def null? : Bool #

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


[View source]
def output_format : Format #

The format that the output should be transcoded into.


[View source]
def output_format=(output_format : Format) #

The format that the output should be transcoded into.


[View source]
def 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.


[View source]
def tab : Bool #

DEPRECATED Use Processor#tab? instead.


[View source]
def tab=(tab : Bool) #

If a tab for each indentation level instead of spaces.


[View source]
def tab? : Bool #

If a tab for each indentation level instead of spaces.


[View source]
def xml_item : String #

The name for XML array elements without keys.


[View source]
def xml_item=(xml_item : String) #

The name for XML array elements without keys.


[View source]
def xml_prolog : Bool #

DEPRECATED Use Processor#xml_prolog? instead.


[View source]
def xml_prolog=(xml_prolog : Bool) #

If the XML prolog should be emitted.


[View source]
def xml_prolog? : Bool #

If the XML prolog should be emitted.


[View source]
def xml_root : String #

The root of the XML document when transcoding to XML.


[View source]
def xml_root=(xml_root : String) #

The root of the XML document when transcoding to XML.


[View source]
def xmlns=(xmlns : Bool) #

If XML namespaces should be parsed as well.

TODO Remove this in oq 2.0 as it'll becomethe default.


[View source]
def xmlns? : Bool #

If XML namespaces should be parsed as well.

TODO Remove this in oq 2.0 as it'll becomethe default.


[View source]