Class: AGI::Response

Description

The answer to every AGI#send is one of these.

Aliases

Old nameNew nameDescription
parenthetical note

Attributes

NameRead/write?Description
code RW The return code, usually (almost always) 200
endpos RW The endpos value (if any)
parenthetical RW The note in parentheses (if any), stripped of parentheses
raw RW Raw response string
result RW The result value (a string)

Public Class methods


new (raw)

raw:A string of the form "200 result=0 [(foo)] [endpos=1234]"

The variables are populated as you would think. The parenthetical note is stripped of its parentheses.

Don‘t forget that result is often an ASCII value rather than an integer value. In that case you should test against ?d where d is a digit.

     # File lib/agi.rb, line 112
112:     def initialize(raw)
113:       @raw = raw
114:       @raw =~ /^(\d+)\s+result=(-?[^\s]*)(?:\s+\((.*)\))?(?:\s+endpos=(-?\d+))?/
115:       @code = ($1 and $1.to_i)
116:       @result = $2
117:       @parenthetical = $3
118:       @endpos = ($4 and $4.to_i)
119:     end