Class: EventMachine::FtpClient::ControlConnection::Response
- Inherits:
-
Object
- Object
- EventMachine::FtpClient::ControlConnection::Response
- Defined in:
- lib/em-ftp-client/control_connection.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #<<(line) ⇒ Object
- #complete? ⇒ Boolean
- #failure? ⇒ Boolean
-
#initialize(code = nil, body = nil) ⇒ Response
constructor
A new instance of Response.
- #mark? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(code = nil, body = nil) ⇒ Response
Returns a new instance of Response.
14 15 16 17 18 19 |
# File 'lib/em-ftp-client/control_connection.rb', line 14 def initialize(code=nil, body=nil) @code = code @body = body @empty = true @complete = false end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/em-ftp-client/control_connection.rb', line 13 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
13 14 15 |
# File 'lib/em-ftp-client/control_connection.rb', line 13 def code @code end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
13 14 15 |
# File 'lib/em-ftp-client/control_connection.rb', line 13 def parent @parent end |
Instance Method Details
#<<(line) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/em-ftp-client/control_connection.rb', line 37 def <<(line) # For an empty response if @empty # If the response is a valid format if line =~ /^[1-5]\d{2}( |-)/ # If the response is multiline if line[3,1] == '-' @code, @body = line.chomp.split('-', 2) # If the response is single line elsif line[3,1] == ' ' @code, @body = line.chomp.split(' ', 2) @complete = true end @empty = false else raise InvalidResponseFormat.new(line.chomp) end # If the response is a continuation of a multiline response else # If this response is terminal if line[0..3] == "#{code} " @body += "\n#{line.chomp.split(' ', 2)[1]}" @complete = true # Otherwise continue hoping and wishing for it to be terminated else @body += "\n#{line.chomp}" end end line end |
#complete? ⇒ Boolean
21 22 23 |
# File 'lib/em-ftp-client/control_connection.rb', line 21 def complete? @complete end |
#failure? ⇒ Boolean
33 34 35 |
# File 'lib/em-ftp-client/control_connection.rb', line 33 def failure? complete? && code && (code[0,1] == "4" || code[0,1] == "5") end |
#mark? ⇒ Boolean
25 26 27 |
# File 'lib/em-ftp-client/control_connection.rb', line 25 def mark? code && code[0,1] == "1" end |
#success? ⇒ Boolean
29 30 31 |
# File 'lib/em-ftp-client/control_connection.rb', line 29 def success? complete? && code && (code[0,1] == "2" || code[0,1] == "3") end |