Class: Twilio::Rails::Phone::Tree::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/twilio/rails/phone/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(say: nil, play: nil, pause: nil, voice: nil, &block) ⇒ Message

Returns a new instance of Message.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/twilio/rails/phone/tree.rb', line 141

def initialize(say: nil, play: nil, pause: nil, voice: nil, &block)
  @say = say.presence
  @play = play.presence
  @pause = pause.presence.to_i
  @pause = nil if @pause == 0
  @voice = voice.presence
  @block = block if block_given?

  raise Twilio::Rails::Phone::InvalidTreeError, "must only have one of say: play: pause:" if (@say && @play) || (@say && @pause) || (@play && @pause)
  raise Twilio::Rails::Phone::InvalidTreeError, "say: must be a string or proc" if @say && !(@say.is_a?(String) || @say.is_a?(Proc))
  raise Twilio::Rails::Phone::InvalidTreeError, "play: must be a string or proc" if @play && !(@play.is_a?(String) || @play.is_a?(Proc))
  raise Twilio::Rails::Phone::InvalidTreeError, "play: be a valid url but is #{ @play }" if @play && @play.is_a?(String) && !@play.match(/^https?:\/\/.+/)
  raise Twilio::Rails::Phone::InvalidTreeError, "pause: must be over zero but is #{ @pause }" if @pause && @pause <= 0
  raise Twilio::Rails::Phone::InvalidTreeError, "block is only valid for say:" if block_given? && (@play || @pause)
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



139
140
141
# File 'lib/twilio/rails/phone/tree.rb', line 139

def block
  @block
end

#valueObject (readonly)

Returns the value of attribute value.



139
140
141
# File 'lib/twilio/rails/phone/tree.rb', line 139

def value
  @value
end

#voiceObject (readonly)

Returns the value of attribute voice.



139
140
141
# File 'lib/twilio/rails/phone/tree.rb', line 139

def voice
  @voice
end

Instance Method Details

#pause?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/twilio/rails/phone/tree.rb', line 165

def pause?
  !!@pause
end

#play?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/twilio/rails/phone/tree.rb', line 161

def play?
  !!@play
end

#say?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/twilio/rails/phone/tree.rb', line 157

def say?
  !!(@say || @block)
end