Class: AGIMenu
- Inherits:
-
Object
- Object
- AGIMenu
- Defined in:
- lib/AGIMenu.rb
Constant Summary collapse
- @@sounds_dir =
''
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #add(digit, sound) ⇒ Object
- #conclusion ⇒ Object
- #conclusion=(conclusion) ⇒ Object
- #digits ⇒ Object (also: #dtmf, #order)
-
#initialize(input = nil) ⇒ AGIMenu
constructor
A new instance of AGIMenu.
- #introduction ⇒ Object
- #introduction=(introduction) ⇒ Object
- #play(conf = {}) ⇒ Object (also: #background, #execute)
- #reorder(new_order, force = false) ⇒ Object
- #timeout ⇒ Object
- #timeout=(timeout) ⇒ Object
Constructor Details
#initialize(input = nil) ⇒ AGIMenu
Returns a new instance of AGIMenu.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/AGIMenu.rb', line 59 def initialize(input=nil) @title = 'AGIMenu:' + self.object_id.to_s @sounds = Hash.new @order = [] @introduction = [] @conclusion = [] @default_timeout = 600 @params=input configure(input) end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
58 59 60 |
# File 'lib/AGIMenu.rb', line 58 def params @params end |
#title ⇒ Object
Returns the value of attribute title.
57 58 59 |
# File 'lib/AGIMenu.rb', line 57 def title @title end |
Class Method Details
.sounds_dir ⇒ Object
137 138 139 |
# File 'lib/AGIMenu.rb', line 137 def AGIMenu.sounds_dir @@sounds_dir end |
.sounds_dir=(dir) ⇒ Object
134 135 136 |
# File 'lib/AGIMenu.rb', line 134 def AGIMenu.sounds_dir=(dir) @@sounds_dir = dir end |
Instance Method Details
#add(digit, sound) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/AGIMenu.rb', line 69 def add(digit, sound) if @order.include?(digit.to_s) then raise AGIMenuFailure.new("Duplicate Digit entry (#{digit.to_s}) in AGIMenu: '#{@title}'") elsif digit.to_s =~ /[0-9#*]/ @sounds[digit.to_s] = [ sound ].flatten @order.push(digit.to_s) else raise AGIMenuFailure.new("Invalid Digit entry (#{digit.to_s}) in AGIMenu: '#{@title}'") end end |
#conclusion ⇒ Object
99 100 101 |
# File 'lib/AGIMenu.rb', line 99 def conclusion @conclusion end |
#conclusion=(conclusion) ⇒ Object
96 97 98 |
# File 'lib/AGIMenu.rb', line 96 def conclusion=(conclusion) @conclusion = [ conclusion ].flatten end |
#digits ⇒ Object Also known as: dtmf, order
79 80 81 |
# File 'lib/AGIMenu.rb', line 79 def digits @order end |
#introduction ⇒ Object
93 94 95 |
# File 'lib/AGIMenu.rb', line 93 def introduction @introduction end |
#introduction=(introduction) ⇒ Object
90 91 92 |
# File 'lib/AGIMenu.rb', line 90 def introduction=(introduction) @introduction = [ introduction ].flatten end |
#play(conf = {}) ⇒ Object Also known as: background, execute
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/AGIMenu.rb', line 110 def play(conf={}) defaults = {:introduction => true, :conclusion => true, :timeout => @default_timeout} conf = defaults.merge(conf) unless conf[:agi].respond_to?(:background) and conf[:agi].respond_to?(:wait_for_digit) raise ArgumentError, ":agi required, must be an AsteriskAGI for AGIMenu.play in AGIMenu: '#{@title}'" end digits = @order.join() audio = [] case when conf[:introduction].class == TrueClass audio << add_introduction when conf[:introduction] audio << add_introduction(conf[:introduction]) end audio << add_body audio << add_conclusion if conf[:conclusion] result = conf[:agi].background(audio.flatten, "'#{digits}'") return result unless result.nil? return result if conf[:timeout].nil? return handle_timeout(conf[:agi], conf[:timeout].to_i) end |
#reorder(new_order, force = false) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/AGIMenu.rb', line 102 def reorder(new_order, force=false) new_order.collect!{ |dtmf| dtmf.to_s } if @order.sort != new_order.sort raise AGIMenuFailure.new("New and old order are incompatible in AGIMenu: '#{@title}'") unless force end @order = new_order end |
#timeout ⇒ Object
87 88 89 |
# File 'lib/AGIMenu.rb', line 87 def timeout @default_timeout end |
#timeout=(timeout) ⇒ Object
84 85 86 |
# File 'lib/AGIMenu.rb', line 84 def timeout=(timeout) @default_timeout = timeout.to_i end |