Class: FCS::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/fcs/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/fcs/response.rb', line 3

def content
  @content
end

#headersObject (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/fcs/response.rb', line 27

def error?
  raw_reply.start_with?('-ERR')
end

#ok?Boolean

Returns:

  • (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_respondObject



12
13
14
15
# File 'lib/fcs/response.rb', line 12

def parse_and_respond
  parse_response
  self
end

#parse_responseObject



17
18
19
20
21
# File 'lib/fcs/response.rb', line 17

def parse_response
  capture_headers
  capture_content
  puts self.inspect
end

#replyObject



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