Class: FCS::Response
- Inherits:
-
Object
- Object
- FCS::Response
- Defined in:
- lib/fcs/response.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(socket) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
- #parse_and_respond ⇒ Object
- #parse_response ⇒ Object
- #reply ⇒ Object
Constructor Details
#initialize(socket) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 |
# File 'lib/fcs/response.rb', line 5 def initialize(socket) @socket = socket @headers = '' @content = '' @content_length = 0 end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
3 4 5 |
# File 'lib/fcs/response.rb', line 3 def content @content end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/fcs/response.rb', line 3 def headers @headers end |
Instance Method Details
#error? ⇒ Boolean
27 28 29 |
# File 'lib/fcs/response.rb', line 27 def error? raw_reply.start_with?('-ERR') end |
#ok? ⇒ Boolean
23 24 25 |
# File 'lib/fcs/response.rb', line 23 def ok? raw_reply.start_with?('+OK') or (@content_length and not error?) end |
#parse_and_respond ⇒ Object
12 13 14 15 |
# File 'lib/fcs/response.rb', line 12 def parse_and_respond parse_response self end |
#parse_response ⇒ Object
17 18 19 20 21 |
# File 'lib/fcs/response.rb', line 17 def parse_response capture_headers capture_content puts self.inspect end |
#reply ⇒ Object
31 32 33 |
# File 'lib/fcs/response.rb', line 31 def reply /^(?:\+OK|\-ERR)\s?(.*)/.match(raw_reply) ? Regexp.last_match(1) : raw_reply end |