summaryrefslogtreecommitdiff
path: root/components/adapter.rb
blob: a79fee63edec97b890a840daccc5b4d98fc2f3ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

require_relative 'embedding'

module NanoBot
  module Components
    class Adapter
      def self.apply(_direction, params)
        content = params[:content]

        raise StandardError, 'conflicting adapters' if %i[fennel lua clojure].count { |key| !params[key].nil? } > 1

        call = { parameters: %w[content], values: [content], safety: false }

        if params[:fennel]
          call[:source] = params[:fennel]
          content = Components::Embedding.fennel(**call)
        elsif params[:clojure]
          call[:source] = params[:clojure]
          content = Components::Embedding.clojure(**call)
        elsif params[:lua]
          call[:source] = params[:lua]
          content = Components::Embedding.lua(**call)
        end

        "#{params[:prefix]}#{content}#{params[:suffix]}"
      end
    end
  end
end