Class: TranslationAPI::Mediator
- Inherits:
-
Object
- Object
- TranslationAPI::Mediator
- Defined in:
- lib/translation_api/mediator.rb
Instance Method Summary collapse
-
#agent_class ⇒ Class
エージェントのクラスを返す.
-
#camelize(str) ⇒ String
スネークケースの文字列をキャメルケースに変換する.
-
#init_agent ⇒ Object
エージェントのインスタンスを初期化する.
- #initialize(output_logs: true, language: "japanese", agent: :openai, except_words: []) ⇒ TranslationAPI::Mediator constructor
-
#translate(text) ⇒ String
テキストを翻訳する.
Constructor Details
#initialize(output_logs: true, language: "japanese", agent: :openai, except_words: []) ⇒ TranslationAPI::Mediator
14 15 16 17 18 19 20 21 |
# File 'lib/translation_api/mediator.rb', line 14 def initialize( output_logs: true, language: "japanese", agent: :openai, except_words: [] ) @output_logs = output_logs @language = language @agent = agent @except_words = except_words end |
Instance Method Details
#agent_class ⇒ Class
エージェントのクラスを返す
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/translation_api/mediator.rb', line 44 def agent_class case @agent when :openai OpenAI when :deepl DeepL else class_name = camelize(@agent.to_s) Object.const_get("TranslationAPI::#{class_name}") end end |
#camelize(str) ⇒ String
スネークケースの文字列をキャメルケースに変換する
60 61 62 |
# File 'lib/translation_api/mediator.rb', line 60 def camelize(str) str.split("_").map(&:capitalize).join end |
#init_agent ⇒ Object
エージェントのインスタンスを初期化する
35 36 37 38 39 |
# File 'lib/translation_api/mediator.rb', line 35 def init_agent agent_class.new( output_logs: @output_logs, except_words: @except_words, language: @language ) end |
#translate(text) ⇒ String
テキストを翻訳する
27 28 29 30 |
# File 'lib/translation_api/mediator.rb', line 27 def translate(text) agent = init_agent agent.translate(text) end |