Class: RecordFile

Inherits:
ReturnStatus show all
Defined in:
lib/ruby-agi/rs/record_file.rb

Instance Method Summary collapse

Methods inherited from ReturnStatus

#command, #command_error?, #message, #result, #return_code, #to_s

Constructor Details

#initialize(command, response) ⇒ RecordFile



47
48
49
# File 'lib/ruby-agi/rs/record_file.rb', line 47

def initialize(command, response)
  super(command, response)
end

Instance Method Details

#digitObject



153
154
155
156
157
158
159
160
161
162
# File 'lib/ruby-agi/rs/record_file.rb', line 153

def digit
  if @digit.nil?
    if interrupted?
      @digit = result.to_i.chr
    end
    @digit = '' if @digit.nil?
  end
  
  return @digit
end

#errorObject



168
169
170
171
172
173
174
# File 'lib/ruby-agi/rs/record_file.rb', line 168

def error
  if random_error?
    return result
  else
    return ''
  end
end

#error?Boolean



176
177
178
# File 'lib/ruby-agi/rs/record_file.rb', line 176

def error?
  return command_error?
end

#failure?Boolean



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ruby-agi/rs/record_file.rb', line 51

def failure?
  if @is_failure.nil?
    if result == '-1'
      @is_failure = true
      rgx_write  = Regexp.new(/\(writefile\)/)
      rgx_waitfor  = Regexp.new(/\(waitfor\)/)
      @is_failure_to_write = rgx_write.match(response).nil?  ? false : true
      @is_failure_on_waitfor = rgx_waitfor.match(response).nil?  ? false : true
    else
      @is_failure = false
    end 
  end

  return @is_failure
end

#failure_on_waitfor?Boolean



75
76
77
78
79
80
81
# File 'lib/ruby-agi/rs/record_file.rb', line 75

def failure_on_waitfor?
  if failure?
    return @is_failure_on_waitfor
  else
    return false
  end
end

#failure_to_write?Boolean



67
68
69
70
71
72
73
# File 'lib/ruby-agi/rs/record_file.rb', line 67

def failure_to_write?
  if failure?
    return @is_failure_to_write
  else
    return false
  end
end

#hangup?Boolean



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ruby-agi/rs/record_file.rb', line 83

def hangup?
  if @is_hangup.nil?
    @is_hangup = false
    if result == '0'
      rgx= Regexp.new(/\(hangup\)/)
      if rgx.match(response)
        @is_hangup = true
      end
    end
  end

  return @is_hangup
end

#interrupted?Boolean



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ruby-agi/rs/record_file.rb', line 97

def interrupted?
  if @is_interrupted.nil?
    @is_interrupted = false
    if ((not failure?) and (result != '0'))
      rgx= Regexp.new(/\(dtmf\)/)
      if rgx.match(response)
        @is_interrupted = true
      end
    end
  end

  return @is_interrupted
end

#offsetObject



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ruby-agi/rs/record_file.rb', line 139

def offset
  if @offset.nil?
    rgx = Regexp.new(/^endpos/)
    response.split(' ').each do | pair |
      if rgx.match(pair)
        @offset = pair.split('=').last
      end
    end
    @offset = '' if @offset.nil?
  end

  return @offset
end

#random_error?Boolean



125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ruby-agi/rs/record_file.rb', line 125

def random_error?
  if @is_random_error.nil?
    @is_random_error = false
    if ((not failure?) and (result != '0'))
      rgx= Regexp.new(/\(randomerror\)/)
      if rgx.match(response)
        @is_randomerror = true
      end
    end
  end

  return @is_randomerror
end

#responseObject



180
181
182
# File 'lib/ruby-agi/rs/record_file.rb', line 180

def response
  return message
end

#success?Boolean



164
165
166
# File 'lib/ruby-agi/rs/record_file.rb', line 164

def success?
  return (not failure?)
end

#timeout?Boolean



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ruby-agi/rs/record_file.rb', line 111

def timeout?
  if @is_timeout.nil?
    @is_timeout = false
    if result == '0'
      rgx= Regexp.new(/\(timeout\)/)
      if rgx.match(response)
        @is_timeout = true
      end
    end
  end

  return @is_timeout
end