Class: Sterlet::Client
- Inherits:
-
Object
- Object
- Sterlet::Client
- Defined in:
- lib/sterlet/client.rb
Instance Method Summary collapse
- #detect(text, hints: []) ⇒ Object
- #dirs ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
-
#langs(ui: :en) ⇒ Object
rubocop:disable Naming/UncommunicativeMethodParamName.
- #translate(text, to:, from: nil, format: :plain) ⇒ Object
Constructor Details
Instance Method Details
#detect(text, hints: []) ⇒ Object
7 8 9 10 |
# File 'lib/sterlet/client.rb', line 7 def detect(text, hints: []) response = @raw_client.detect(text, hints: hints) response['lang'].to_sym end |
#dirs ⇒ Object
18 19 20 |
# File 'lib/sterlet/client.rb', line 18 def dirs @raw_client.get_langs['dirs'].map { |x| x.split('-').map(&:to_sym) } end |
#langs(ui: :en) ⇒ Object
rubocop:disable Naming/UncommunicativeMethodParamName
23 24 25 |
# File 'lib/sterlet/client.rb', line 23 def langs(ui: :en) @raw_client.get_langs(ui: ui)['langs'].map { |k, v| [k.to_sym, v] }.to_h.freeze end |
#translate(text, to:, from: nil, format: :plain) ⇒ Object
12 13 14 15 16 |
# File 'lib/sterlet/client.rb', line 12 def translate(text, to:, from: nil, format: :plain) lang = from ? [from, to].join('-') : to response = @raw_client.translate(text, lang: lang, format: format) response['text'].join(' ') end |