Module: Translatomatic::Provider
- Extended by:
- Util
- Defined in:
- lib/translatomatic/provider.rb,
lib/translatomatic/provider/base.rb,
lib/translatomatic/provider/google.rb,
lib/translatomatic/provider/yandex.rb,
lib/translatomatic/provider/frengly.rb,
lib/translatomatic/provider/microsoft.rb,
lib/translatomatic/provider/my_memory.rb,
lib/translatomatic/provider/google_web.rb
Overview
Provides methods to access and create instances of interfaces to translation APIs.
Defined Under Namespace
Classes: Base, Frengly, Google, GoogleWeb, Microsoft, MyMemory, Yandex
Class Method Summary collapse
-
.available(options = {}) ⇒ Array<#translate>
Find all configured providers.
-
.find(name) ⇒ Class
The provider class corresponding to the given name.
-
.get_error(name) ⇒ Object
Get errors for the specified provider.
-
.names ⇒ List<String>
A list of all providers.
-
.resolve(list, options = {}) ⇒ Array<Translatomatic::Provider::Base>
Resolve the given list of provider names to a list of providers.
-
.types ⇒ List<Class>
A list of all provider classes.
Class Method Details
.available(options = {}) ⇒ Array<#translate>
Find all configured providers
51 52 53 54 |
# File 'lib/translatomatic/provider.rb', line 51 def available( = {}) available = types.collect { |klass| create_provider(klass, ) } available.compact end |
.find(name) ⇒ Class
Returns The provider class corresponding to the given name.
9 10 11 12 |
# File 'lib/translatomatic/provider.rb', line 9 def find(name) load_providers name && !name.empty? ? const_get(name) : nil end |
.get_error(name) ⇒ Object
Get errors for the specified provider
58 59 60 |
# File 'lib/translatomatic/provider.rb', line 58 def get_error(name) @provider_errors[name] end |
.names ⇒ List<String>
Returns A list of all providers.
44 45 46 |
# File 'lib/translatomatic/provider.rb', line 44 def names types.collect { |i| i.name.demodulize } end |
.resolve(list, options = {}) ⇒ Array<Translatomatic::Provider::Base>
Resolve the given list of provider names to a list of providers. If the list is empty, return all providers that are configured.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/translatomatic/provider.rb', line 19 def resolve(list, = {}) list = [list].flatten.compact.collect do |provider| if provider.respond_to?(:translate) provider else klass = find(provider) provider = create_provider(klass, ) end provider end # if we didn't resolve to any providers, find all available # providers that work with the given options. list.empty? ? available() : list end |
.types ⇒ List<Class>
Returns A list of all provider classes.
36 37 38 39 40 41 |
# File 'lib/translatomatic/provider.rb', line 36 def types load_providers constants.collect { |c| const_get(c) }.select do |klass| klass.is_a?(Class) && klass != Translatomatic::Provider::Base end end |