Class: YandexSpeechApi::Language

Inherits:
Object
  • Object
show all
Defined in:
lib/yandex_speech/language.rb

Direct Known Subclasses

English, Russian, Turkey, Ukrain

Defined Under Namespace

Classes: AbstractClassCreationError, English, Russian, Turkey, Ukrain, UnknownLanguageError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.buildRussian, ...

Language object constructor.


40
41
42
43
44
45
46
# File 'lib/yandex_speech/language.rb', line 40

def build
  if to_s.split('::').last == 'Language'
    raise AbstractClassCreationError
  else
    new
  end
end

.init(language = :english) ⇒ Russian, ...

Determines class by language param and creates instance for that class.


25
26
27
28
29
30
# File 'lib/yandex_speech/language.rb', line 25

def init(language = :english)
  klass = const_get language.capitalize.to_sym
  klass.build
rescue NameError
  raise UnknownLanguageError, language
end

.listArray<Classes>

List of allowed languages


53
54
55
56
57
# File 'lib/yandex_speech/language.rb', line 53

def list
  @cached_list ||=
    constants.select { |name| const_get(name).class === Class }
             .reject { |name| name =~ /Error/ }
end

Instance Method Details

#codeString

Abstract. Child should override this and return language code.


80
81
82
# File 'lib/yandex_speech/language.rb', line 80

def code
  raise 'abstract method called'
end

#to_sObject

Pretty format.


67
68
69
# File 'lib/yandex_speech/language.rb', line 67

def to_s
  self.class.to_s.split('::').last
end