Sha256: 241bb0db93bccfdec84bb385fed40911fa8a3adde62a03df9420f48170ba77c2

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 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
  # A Boxcar executes ruby code to do math
  class RubyCalculator < Boxcar
    # the description of this engine boxcar
    CALCDESC = "will run a ruby calculation to answer a math question"

    # @param kwargs [Hash] Any other keyword arguments to pass to the parent class.
    def initialize(**kwargs)
      kwargs[:name] ||= "RubyCalculator"
      kwargs[:description] ||= CALCDESC
      kwargs[:parameters] ||= default_params

      super
    end

    def default_params
      { question: {
          type: :string,
          description: "a Ruby programming string that will compute the answer to a math question",
          required: true
          } }
    end

    # run a ruby calculator question
    # @param question [String] The question to ask Google.
    # @return [String] The answer to the question.
    def run(question)
      code = "puts(#{question})"
      ruby_executor = Boxcars::RubyREPL.new
      rv = ruby_executor.call(code: code)
      puts "Question: #{question}"
      puts "Answer: #{rv}"
      rv
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
boxcars-0.7.2 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.7.1 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.6.9 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.6.8 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.6.7 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.6.6 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.6.5 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.6.4 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.6.3 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.6.2 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.6.1 lib/boxcars/boxcar/ruby_calculator.rb
boxcars-0.5.1 lib/boxcars/boxcar/ruby_calculator.rb