Class RADP
In: lib/radp.rb
Parent: Object

Ruby Asterisk Dial Plan generator

Methods

app   context   ext   includes   method_missing   new   switch  

External Aliases

p -> priority

Attributes

p  [RW]  The current priority

Public Class methods

io can be anything that accepts <<

[Source]

# File lib/radp.rb, line 8
  def initialize(io=$stdout,&block)
    @io = io
    @io << "; Generated by radp (http://hans.fugal.net/src/radp)\n"
    @state = :top
    yield(self) if block_given?
  end

Public Instance methods

An Asterisk application (e.g. Dial(‘ZAP/1’,20))

[Source]

# File lib/radp.rb, line 48
  def app(name,*args)
    raise "Can't have an application here" unless @state == :ext
    p = @p.to_i
    @io << "exten => #{@extension},#{p},#{name}(#{args.join ','})\n"
    @p += 1
    return p
  end

Begin a new context

[Source]

# File lib/radp.rb, line 16
  def context(name)
    raise "Can't have a context here" unless @state == :top
    @state = :context
    @io << "[#{name}]\n"
    yield(self) if block_given?
    @io << "\n"
    @state = :top
  end

Begin a new extension

[Source]

# File lib/radp.rb, line 26
  def ext(name)
    raise "Can't have an extension here" unless @state == :context
    @state = :ext
    @extension = name
    @p = 1
    yield(self) if block_given?
    @state = :context
  end

Asterisk include directive

[Source]

# File lib/radp.rb, line 36
  def includes(name)
    raise "Can't have an includes here" unless @state == :context
    @io << "include => #{name}\n"
  end

For creating applications

[Source]

# File lib/radp.rb, line 57
  def method_missing(name,*args,&block)
    if @state == :ext
      app(name,args) 
    else
      super
    end
  end

Asterisk switch directive

[Source]

# File lib/radp.rb, line 42
  def switch(name)
    raise "Can't have a switch here" unless @state == :context
    @io << "switch => #{name}\n"
  end

[Validate]