Module: Net::NNTP::BodyBaseResponse
- Included in:
- ArticleResponse, BodyResponse, GroupListResponse, GroupSelected, HdrResponse, HeaderResponse, InformationResponse, NewnewsResponse, OverviewInformation
- Defined in:
- lib/net/nntp/response.rb
Overview
Prepares the basic functionality for responses that have a body (directly following the status line).
Every class that includes this can use strings or objects responding to readline
to retrieve the body.
Instance Method Summary collapse
-
#body ⇒ Object
Returns the body attribute.
-
#body=(body) ⇒ Object
Sets the body attribute.
-
#parse_body ⇒ Object
Is called from body= and should be used to set the @body attribute transforming the contents of the @raw attribute.
Instance Method Details
#body ⇒ Object
Returns the body attribute.
If a block is given, the results will be sent to body= before returning the attribute.
50 51 52 53 |
# File 'lib/net/nntp/response.rb', line 50 def body self.body = yield if block_given? @body end |
#body=(body) ⇒ Object
Sets the body attribute.
The parameter body
can be a string or an object responding to readline
. Reading will be halted at a line with a single dot followed by <CRLF> or <LF>, or when an EOFError occurs. The result will be stored in the internal attribute @raw. Subsequently, parse_body will be called.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/net/nntp/response.rb', line 31 def body=(body) if body.respond_to? :readline begin @raw = '' loop do line = body.readline @raw << line break if line =~/\A\.\r?\n\z/m end rescue EOFError => e end else @raw = body end parse_body end |
#parse_body ⇒ Object
Is called from body= and should be used to set the @body attribute transforming the contents of the @raw attribute.
56 57 58 |
# File 'lib/net/nntp/response.rb', line 56 def parse_body @body = @raw.dup end |