Class: YandexSpeechApi::Key

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

Defined Under Namespace

Classes: InvalidGlobalKey, KeyNotDefined

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = :unknown) ⇒ Key



39
40
41
# File 'lib/yandex_speech/key.rb', line 39

def initialize(key = :unknown)
  @instance_key = key
end

Class Attribute Details

.global_key=(new_key) ⇒ Object

Sets global key.

Parameters:

  • new_key (Key, Symbol)

Raises:


14
15
16
17
18
19
# File 'lib/yandex_speech/key.rb', line 14

def global_key=(new_key)
  key_tmp = new_key.is_a?(Key) ? new_key : Key.new(new_key)

  raise InvalidGlobalKey, key_tmp unless key_tmp.present?
  @global_key = key_tmp
end

Class Method Details

.global_key?TrueClass, FalseClass

otherwise return false.

Returns:

  • (TrueClass, FalseClass)

    true if global key set,


25
26
27
# File 'lib/yandex_speech/key.rb', line 25

def global_key?
  !!global_key
end

Instance Method Details

#getKey

Returns an key.

Returns:


51
52
53
54
55
56
57
58
59
# File 'lib/yandex_speech/key.rb', line 51

def get
  if present?
    return instance_key
  elsif default?
    return default.get
  else
    raise KeyNotDefined
  end
end

#present?TrueClass, FalseClass

Key present?

Returns:

  • (TrueClass, FalseClass)

    returns false if key is :unknown, otherwise - true.


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

def present?
  !(instance_key == :unknown)
end