Class: Clova::OutputSpeech

Inherits:
Object
  • Object
show all
Defined in:
lib/clova-speech/output_speech.rb

Defined Under Namespace

Classes: SpeechInfoObject

Instance Method Summary collapse

Constructor Details

#initializeOutputSpeech

Returns a new instance of OutputSpeech.



3
4
5
6
# File 'lib/clova-speech/output_speech.rb', line 3

def initialize
  @lang = 'ja'
  @speech_info_objects = []
end

Instance Method Details

#add_speech(value:, type: 'PlainText', language: @lang) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/clova-speech/output_speech.rb', line 16

def add_speech(value:, type:'PlainText', language: @lang)
  case type
  when 'PlainText'
    lang = language
  when 'URL'
    lang = ''
  end
  @speech_info_objects << SpeechInfoObject.new(lang: lang, value:value, type:type)
end

#as_jsonObject



8
9
10
# File 'lib/clova-speech/output_speech.rb', line 8

def as_json
  {type: type, values: values}
end

#empty?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/clova-speech/output_speech.rb', line 12

def empty?
  @speech_info_objects.empty?
end

#simple_speech?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/clova-speech/output_speech.rb', line 26

def simple_speech?
  @speech_info_objects.one?
end

#speech_list?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/clova-speech/output_speech.rb', line 30

def speech_list?
  !simple_speech?
end

#typeObject



34
35
36
37
38
39
40
41
# File 'lib/clova-speech/output_speech.rb', line 34

def type
  case
  when simple_speech? then 'SimpleSpeech'
  when speech_list? then 'SpeechList'
  else
    raise 'Type not found'
  end
end

#valuesObject



43
44
45
46
47
48
49
50
# File 'lib/clova-speech/output_speech.rb', line 43

def values
  case
  when simple_speech?
    @speech_info_objects.first.as_json
  when speech_list?
    @speech_info_objects.map(&:as_json)
  end
end