module Y::Translate
Constants
- VERSION
Attributes
configuration[W]
Public Class Methods
configuration()
click to toggle source
# File lib/y/translate.rb, line 11 def self.configuration @configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
# File lib/y/translate.rb, line 15 def self.configure yield(configuration) API.key = configuration.api_key end
detect(text)
click to toggle source
# File lib/y/translate.rb, line 42 def self.detect(text) request(API::METHOD_DETECT, text: text)['lang'] end
get_langs()
click to toggle source
# File lib/y/translate.rb, line 28 def self.get_langs request( API::METHOD_GET_LANGS, ui: configuration.lang_to )['dirs'] end
get_langs_names()
click to toggle source
# File lib/y/translate.rb, line 35 def self.get_langs_names request( API::METHOD_GET_LANGS, ui: configuration.lang_to )['langs'] end
reset_default()
click to toggle source
# File lib/y/translate.rb, line 20 def self.reset_default api_key = configuration.api_key @configuration = Configuration.new configure do |config| config.api_key = api_key end end
translate(text, params = {})
click to toggle source
# File lib/y/translate.rb, line 46 def self.translate(text, params = {}) params[:text] = text params[:lang] = configuration.lang_to unless params.key?(:lang) response = request(API::METHOD_TRANSLATE, params)['text'] response = response[0] if response.count == 1 response end
Private Class Methods
request(method, params)
click to toggle source
# File lib/y/translate.rb, line 56 def self.request(method, params) API.request(:post, method, params) end