Class: EventMachine::FtpClient::ControlConnection::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/em-ftp-client/control_connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



13
14
15
# File 'lib/em-ftp-client/control_connection.rb', line 13

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



13
14
15
# File 'lib/em-ftp-client/control_connection.rb', line 13

def code
  @code
end

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

Returns:

  • (Boolean)


21
22
23
# File 'lib/em-ftp-client/control_connection.rb', line 21

def complete?
  @complete
end

#failure?Boolean

Returns:

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/em-ftp-client/control_connection.rb', line 25

def mark?
  code && code[0,1] == "1"
end

#success?Boolean

Returns:

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