lib/boxcars/boxcar/calculator.rb in boxcars-0.2.0 vs lib/boxcars/boxcar/calculator.rb in boxcars-0.2.1

- old
+ new

@@ -11,32 +11,30 @@ # @param prompt [Boxcars::Prompt] The prompt to use for this boxcar. Defaults to built-in prompt. # @param kwargs [Hash] Any other keyword arguments to pass to the parent class. def initialize(engine: nil, prompt: nil, **kwargs) the_prompt = prompt || my_prompt kwargs[:stop] ||= ["```output"] - super(name: kwargs[:name] || "Calculator", - description: kwargs[:description] || CALCDESC, - engine: engine, - prompt: the_prompt, - **kwargs) + kwargs[:name] ||= "Calculator" + kwargs[:description] ||= CALCDESC + super(engine: engine, prompt: the_prompt, **kwargs) end private def get_embedded_ruby_answer(text) code = text[8..-4].split("```").first.strip ruby_executor = Boxcars::RubyREPL.new - ruby_executor.call(code: code).strip + ruby_executor.call(code: code) end def get_answer(text) case text when /^```ruby/ get_embedded_ruby_answer(text) when /^Answer:/ - text + Result.from_text(text) else - raise Boxcars::Error "Unknown format from engine: #{text}" + Result.new(status: :error, explanation: "Unknown format from engine: #{text}") end end # our template # rubocop:disable Style/RedundantHeredocDelimiterQuotes