summaryrefslogtreecommitdiff
path: root/controllers/interfaces/eval.rb
diff options
context:
space:
mode:
Diffstat (limited to 'controllers/interfaces/eval.rb')
-rw-r--r--controllers/interfaces/eval.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/controllers/interfaces/eval.rb b/controllers/interfaces/eval.rb
new file mode 100644
index 0000000..6cb12b4
--- /dev/null
+++ b/controllers/interfaces/eval.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require 'pry'
+require 'rainbow'
+
+require_relative '../../logic/helpers/hash'
+
+module NanoBot
+ module Controllers
+ module Interfaces
+ module Eval
+ def self.evaluate(input, cartridge, session)
+ prefix = build_prefix(cartridge)
+ postfix = build_postfix(cartridge)
+
+ session.print(prefix) unless prefix.nil?
+
+ session.evaluate_and_print(input, mode: 'eval')
+
+ session.print(postfix) unless postfix.nil?
+ end
+
+ def self.build_prefix(cartridge)
+ eval_interface = Logic::Helpers::Hash.fetch(cartridge, %i[interfaces eval])
+ return nil if eval_interface.nil?
+ eval_interface[:prefix]
+ end
+
+ def self.build_postfix(cartridge)
+ eval_interface = Logic::Helpers::Hash.fetch(cartridge, %i[interfaces eval])
+ return "\n" if eval_interface.nil? || !eval_interface.key?(:postfix) # default
+ eval_interface[:postfix]
+ end
+ end
+ end
+ end
+end