Class: AGIResponse
- Inherits:
-
Object
- Object
- AGIResponse
- Defined in:
- lib/AGIResponse.rb
Overview
AGIResponse implements a simple response object which stores Asterisk’s native result, and provided data, to be evaluated in various ways.
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#native ⇒ Object
Returns the value of attribute native.
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
-
#%(rvalue) ⇒ Object
Allow modulus of numbers (Integer, Float, Fixnum).
-
#*(rvalue) ⇒ Object
Allow multiplication of numbers (Integer, Float, Fixnum).
-
#**(rvalue) ⇒ Object
Allow exponentiation of numbers (Integer, Float, Fixnum).
-
#+(rvalue) ⇒ Object
Allow addition for numbers (Integer, Float, Fixnum).
-
#-(rvalue) ⇒ Object
Allow subtraction for numbers (Integer, Float, Fixnum).
-
#/(rvalue) ⇒ Object
Allow division of numbers (Integer, Float, Fixnum).
-
#==(string) ⇒ Object
Allows the object to be compared for equality.
-
#=~(regexp) ⇒ Object
Allows the response object to be compared with a regular expression, if possible.
-
#initialize ⇒ AGIResponse
constructor
A new instance of AGIResponse.
-
#nil? ⇒ Boolean
Check to see if the object is nil returns whether the data is nil.
-
#success? ⇒ Boolean
Can check the response object to see if the associated command was successful.
-
#to_i ⇒ Object
Allows the response object to be evaluated as an integer, returning the data if it can be evaluated as such.
-
#to_s ⇒ Object
(also: #to_str)
Allows the response object to be evaluated as a string, returning the data.
Constructor Details
#initialize ⇒ AGIResponse
Returns a new instance of AGIResponse.
37 38 39 40 41 |
# File 'lib/AGIResponse.rb', line 37 def initialize @native = nil @data = nil @success = false end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
36 37 38 |
# File 'lib/AGIResponse.rb', line 36 def data @data end |
#native ⇒ Object
Returns the value of attribute native.
36 37 38 |
# File 'lib/AGIResponse.rb', line 36 def native @native end |
#success ⇒ Object
Returns the value of attribute success.
36 37 38 |
# File 'lib/AGIResponse.rb', line 36 def success @success end |
Instance Method Details
#%(rvalue) ⇒ Object
Allow modulus of numbers (Integer, Float, Fixnum)
113 114 115 116 |
# File 'lib/AGIResponse.rb', line 113 def %(rvalue) values = coerce(rvalue) return ( values[1] % values[0]) end |
#*(rvalue) ⇒ Object
Allow multiplication of numbers (Integer, Float, Fixnum)
95 96 97 98 |
# File 'lib/AGIResponse.rb', line 95 def *(rvalue) values = coerce(rvalue) return ( values[1] * values[0]) end |
#**(rvalue) ⇒ Object
Allow exponentiation of numbers (Integer, Float, Fixnum)
107 108 109 110 |
# File 'lib/AGIResponse.rb', line 107 def **(rvalue) values = coerce(rvalue) return ( values[1] ** values[0]) end |
#+(rvalue) ⇒ Object
Allow addition for numbers (Integer, Float, Fixnum)
83 84 85 86 |
# File 'lib/AGIResponse.rb', line 83 def +(rvalue) values = coerce(rvalue) return ( values[1] + values[0]) end |
#-(rvalue) ⇒ Object
Allow subtraction for numbers (Integer, Float, Fixnum)
89 90 91 92 |
# File 'lib/AGIResponse.rb', line 89 def -(rvalue) values = coerce(rvalue) return ( values[1] - values[0]) end |
#/(rvalue) ⇒ Object
Allow division of numbers (Integer, Float, Fixnum)
101 102 103 104 |
# File 'lib/AGIResponse.rb', line 101 def /(rvalue) values = coerce(rvalue) return ( values[1] / values[0]) end |
#==(string) ⇒ Object
Allows the object to be compared for equality.
68 69 70 |
# File 'lib/AGIResponse.rb', line 68 def ==(string) @data == string end |
#=~(regexp) ⇒ Object
Allows the response object to be compared with a regular expression, if possible
58 59 60 61 62 63 64 65 |
# File 'lib/AGIResponse.rb', line 58 def =~(regexp) return unless regexp.instance_of?(Regexp) if @data.respond_to?(:to_s) return @data.to_s =~ regexp else return nil end end |
#nil? ⇒ Boolean
Check to see if the object is nil returns whether the data is nil
78 79 80 |
# File 'lib/AGIResponse.rb', line 78 def nil? @data.nil? end |
#success? ⇒ Boolean
Can check the response object to see if the associated command was successful.
73 74 75 |
# File 'lib/AGIResponse.rb', line 73 def success? @success end |
#to_i ⇒ Object
Allows the response object to be evaluated as an integer, returning the data if it can be evaluated as such
49 50 51 52 53 54 55 |
# File 'lib/AGIResponse.rb', line 49 def to_i if @data.respond_to?(:to_i) return @data.to_i else return nil end end |
#to_s ⇒ Object Also known as: to_str
Allows the response object to be evaluated as a string, returning the data.
43 44 45 |
# File 'lib/AGIResponse.rb', line 43 def to_s return @data.to_s end |