class Ralyxa::ResponseBuilder

Public Class Methods

build(options = {}, response_class = Ralyxa::ResponseEntities::Response, output_speech_class = Ralyxa::ResponseEntities::OutputSpeech, reprompt_class = Ralyxa::ResponseEntities::Reprompt) click to toggle source
# File lib/ralyxa/response_builder.rb, line 13
def self.build(options = {}, response_class = Ralyxa::ResponseEntities::Response, output_speech_class = Ralyxa::ResponseEntities::OutputSpeech, reprompt_class = Ralyxa::ResponseEntities::Reprompt)
  new(response_class, output_speech_class, reprompt_class, options).build
end
new(response_class, output_speech_class, reprompt_class, options) click to toggle source
# File lib/ralyxa/response_builder.rb, line 6
def initialize(response_class, output_speech_class, reprompt_class, options)
  @response_class      = response_class
  @output_speech_class = output_speech_class
  @reprompt_class      = reprompt_class
  @options             = options
end

Public Instance Methods

build() click to toggle source
# File lib/ralyxa/response_builder.rb, line 17
def build
  merge_output_speech if response_text_exists?
  merge_reprompt if reprompt_exists?
  merge_card if card_exists?

  @response_class.as_hash(@options).to_json
end

Private Instance Methods

card_exists?() click to toggle source
# File lib/ralyxa/response_builder.rb, line 39
def card_exists?
  @options[:card]
end
merge_card() click to toggle source
# File lib/ralyxa/response_builder.rb, line 35
def merge_card
  @options[:card] = @options[:card].to_h
end
merge_output_speech() click to toggle source
# File lib/ralyxa/response_builder.rb, line 27
def merge_output_speech
  @options.merge!(output_speech: output_speech)
end
merge_reprompt() click to toggle source
# File lib/ralyxa/response_builder.rb, line 31
def merge_reprompt
  @options.merge!(reprompt: reprompt)
end
output_speech() click to toggle source
# File lib/ralyxa/response_builder.rb, line 51
def output_speech
  output_speech_params = { speech: @options.delete(:response_text) }
  output_speech_params[:ssml] = @options.delete(:ssml) if @options[:ssml]

  @output_speech_class.as_hash(output_speech_params)
end
reprompt() click to toggle source
# File lib/ralyxa/response_builder.rb, line 58
def reprompt
  reprompt_params = { reprompt_speech: @options.delete(:reprompt) }
  reprompt_params[:reprompt_ssml] = @options.delete(:reprompt_ssml) if @options[:reprompt_ssml]

  @reprompt_class.as_hash(reprompt_params)
end
reprompt_exists?() click to toggle source
# File lib/ralyxa/response_builder.rb, line 47
def reprompt_exists?
  @options[:reprompt]
end
response_text_exists?() click to toggle source
# File lib/ralyxa/response_builder.rb, line 43
def response_text_exists?
  @options[:response_text]
end