Class: Net::NNTPGenericRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/net/nntp/request.rb

Direct Known Subclasses

NNTPRequest

Constant Summary collapse

RESPONSES =
::Net::NNTP_RESPONSES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ NNTPGenericRequest


10
11
12
# File 'lib/net/nntp/request.rb', line 10

def initialize(raw)
  @raw = raw
end

Instance Attribute Details

#rawString (readonly)


8
9
10
# File 'lib/net/nntp/request.rb', line 8

def raw
  @raw
end

Instance Method Details

#response_class(code) ⇒ Object

Raises:

  • (Exception)

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/net/nntp/request.rb', line 14

def response_class(code)
  klass = self.class

  # traverse the ancestor chain until we find a valid response
  while klass.constants.include?(:RESPONSES)
    klass::RESPONSES.each do |key, resp_klass|
      if key.is_a?(Fixnum)
        return resp_klass if key == code
      elsif key.is_a?(Range)
        return resp_klass if key.include?(code)
      end
    end

    klass = klass.superclass
  end

  raise Exception, 'could not find a valid response'
end