Sha256: 0330f5c19f54f3cc19b4c15cd87f48fa17de91c3eefd7eafa0f8ed0896c9372c

Contents?: true

Size: 1.19 KB

Versions: 21

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

# Boxcars is a framework for running a series of tools to get an answer to a question.
module Boxcars
  # For Boxcars that use an engine to do their work.
  class XMLEngineBoxcar < EngineBoxcar
    # An XML Engine Boxcar is a container for a single tool to run.

    # Parse out the action and input from the engine output.
    # @param engine_output [String] The output from the engine.
    # @return [Array<String>] The action and input.
    def get_answer(engine_output)
      xn_get_answer(XNode.from_xml(engine_output))
    rescue StandardError => e
      Result.from_error("Error: #{e.message}:\n#{engine_output}")
    end

    # get answer an XNode
    # @param xnode [XNode] The XNode to use.
    # @return [Array<String, String>] The action and input.
    def xn_get_answer(xnode)
      reply = xnode.xtext("//reply")

      if reply.present?
        Result.new(status: :ok, answer: reply, explanation: reply)
      else
        # we have an unexpected output from the engine
        Result.new(status: :error, answer: nil,
                   explanation: "You gave me an improperly formatted answer or didn't use tags. I was expecting a reply.")
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
boxcars-0.7.3 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.7.2 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.7.1 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.6.9 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.6.8 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.6.7 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.6.6 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.6.5 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.6.4 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.6.3 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.6.2 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.6.1 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.5.1 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.4.10 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.4.9 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.4.8 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.4.7 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.4.6 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.4.5 lib/boxcars/boxcar/xml_engine_boxcar.rb
boxcars-0.4.4 lib/boxcars/boxcar/xml_engine_boxcar.rb