Class: Adhearsion::Asterisk::ConfigGenerator::Voicemail

Inherits:
Adhearsion::Asterisk::ConfigGenerator show all
Defined in:
lib/adhearsion/asterisk/config_generator/voicemail.rb

Defined Under Namespace

Classes: ContextDefinition, EmailDefinition, RecordingDefinition

Constant Summary collapse

DEFAULT_GENERAL_SECTION =
{
  :format => :wav
}
STATIC_ZONEMESSAGES_CONTEXT =

Don't worry. These will be overridable soon.

<<-ZONEMESSAGES.strip_heredoc
  [zonemessages]
  eastern=America/New_York|'vm-received' Q 'digits/at' IMp
  central=America/Chicago|'vm-received' Q 'digits/at' IMp
  central24=America/Chicago|'vm-received' q 'digits/at' H N 'hours'
  military=Zulu|'vm-received' q 'digits/at' H N 'hours' 'phonetic/z_p'
  european=Europe/Copenhagen|'vm-received' a d b 'digits/at' HM
ZONEMESSAGES

Constants inherited from Adhearsion::Asterisk::ConfigGenerator

SECTION_TITLE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Adhearsion::Asterisk::ConfigGenerator

create_sanitary_hash_from, #to_sanitary_hash, warning_message

Constructor Details

#initializeVoicemail

Returns a new instance of Voicemail.


23
24
25
26
27
28
# File 'lib/adhearsion/asterisk/config_generator/voicemail.rb', line 23

def initialize
  @properties = DEFAULT_GENERAL_SECTION.clone
  @mailboxes  = {}
  @context_definitions = []
  super
end

Instance Attribute Details

#context_definitionsObject (readonly)

Returns the value of attribute context_definitions


22
23
24
# File 'lib/adhearsion/asterisk/config_generator/voicemail.rb', line 22

def context_definitions
  @context_definitions
end

#propertiesObject (readonly)

Returns the value of attribute properties


22
23
24
# File 'lib/adhearsion/asterisk/config_generator/voicemail.rb', line 22

def properties
  @properties
end

Instance Method Details

#context(name) ⇒ Object

Raises:

  • (ArgumentError)

30
31
32
33
34
35
36
37
38
# File 'lib/adhearsion/asterisk/config_generator/voicemail.rb', line 30

def context(name)
  raise ArgumentError, "Name cannot be 'general'!" if name.to_s.downcase == 'general'
  raise ArgumentError, "A name can only be characters, numbers, and underscores!" if name.to_s !~ /^[\w_]+$/

  ContextDefinition.new(name).tap do |context_definition|
    yield context_definition
    context_definitions << context_definition
  end
end

#emailsObject


54
55
56
57
58
59
60
61
# File 'lib/adhearsion/asterisk/config_generator/voicemail.rb', line 54

def emails
  @emails ||= EmailDefinition.new
  if block_given?
    yield @emails
  else
    @emails
  end
end

#execute_on_pin_change(command) ⇒ Object


44
45
46
# File 'lib/adhearsion/asterisk/config_generator/voicemail.rb', line 44

def execute_on_pin_change(command)
  string "externpass" => command
end

#greeting_maximum(seconds) ⇒ Object


40
41
42
# File 'lib/adhearsion/asterisk/config_generator/voicemail.rb', line 40

def greeting_maximum(seconds)
  int "maxgreet" => seconds
end

#recordings {|@recordings| ... } ⇒ Object

Yields:


48
49
50
51
52
# File 'lib/adhearsion/asterisk/config_generator/voicemail.rb', line 48

def recordings
  @recordings ||= RecordingDefinition.new
  yield @recordings if block_given?
  @recordings
end

#to_sObject


63
64
65
66
67
68
69
70
# File 'lib/adhearsion/asterisk/config_generator/voicemail.rb', line 63

def to_s
  email_properties = @emails ? @emails.properties : {}
  ConfigGenerator.warning_message +
  "[general]\n" +
  properties.merge(email_properties).map { |(key,value)| "#{key}=#{value}" }.sort.join("\n") + "\n\n" +
  STATIC_ZONEMESSAGES_CONTEXT +
  context_definitions.map(&:to_s).join("\n\n")
end