Class: Snarl::SNP::Response
- Inherits:
-
Object
- Object
- Snarl::SNP::Response
- Defined in:
- lib/snarl/snp/response.rb
Constant Summary collapse
- ResponseParseRegexp =
/\ASNP\/[\d\.]+\/(\d+)\/(.+?)\Z/
Instance Attribute Summary collapse
-
#code ⇒ Object
(also: #status)
readonly
Returns the value of attribute code.
-
#infomation ⇒ Object
readonly
Returns the value of attribute infomation.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(s) ⇒ Response
constructor
A new instance of Response.
-
#inspect ⇒ Object
p response #=> “SNP/1.1/0/OK/456”.
- #ok? ⇒ Boolean
- #parse_response ⇒ Object
- #request_str ⇒ Object
-
#to_s ⇒ Object
puts response #=> “0”.
Constructor Details
#initialize(s) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 |
# File 'lib/snarl/snp/response.rb', line 5 def initialize(s) if s.respond_to?(:get) then @response = s.get else @response = s end parse_response end |
Instance Attribute Details
#code ⇒ Object (readonly) Also known as: status
Returns the value of attribute code.
14 15 16 |
# File 'lib/snarl/snp/response.rb', line 14 def code @code end |
#infomation ⇒ Object (readonly)
Returns the value of attribute infomation.
14 15 16 |
# File 'lib/snarl/snp/response.rb', line 14 def infomation @infomation end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
14 15 16 |
# File 'lib/snarl/snp/response.rb', line 14 def @message end |
#request ⇒ Object
Returns the value of attribute request.
15 16 17 |
# File 'lib/snarl/snp/response.rb', line 15 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
14 15 16 |
# File 'lib/snarl/snp/response.rb', line 14 def response @response end |
Instance Method Details
#error ⇒ Object
28 |
# File 'lib/snarl/snp/response.rb', line 28 def error ; Error.klass(self.code) ; end |
#inspect ⇒ Object
p response #=> “SNP/1.1/0/OK/456”
31 |
# File 'lib/snarl/snp/response.rb', line 31 def inspect ; @response.chomp ; end |
#ok? ⇒ Boolean
33 |
# File 'lib/snarl/snp/response.rb', line 33 def ok? ; code.to_i.zero? ; end |
#parse_response ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/snarl/snp/response.rb', line 18 def parse_response if ResponseParseRegexp =~ @response.chomp then @code = $1 @message, @infomation= $2.split(/\//) else raise Snarl::SNP::Error::RUBYSNARL_UNKNOWN_RESPONSE.new(self, nil) end raise error.new(self, nil) unless ok? end |
#request_str ⇒ Object
34 |
# File 'lib/snarl/snp/response.rb', line 34 def request_str ; request ? request.to_s : nil ; end |
#to_s ⇒ Object
puts response #=> “0”
30 |
# File 'lib/snarl/snp/response.rb', line 30 def to_s ; code ; end |