Class: Minver::Parser
- Inherits:
-
Object
- Object
- Minver::Parser
- Defined in:
- lib/minver/parser.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #body ⇒ Object
- #data ⇒ Object
- #headers ⇒ Object
- #http_method ⇒ Object
-
#initialize(stream_or_string) ⇒ Parser
constructor
A new instance of Parser.
- #path ⇒ Object
- #query_string ⇒ Object
- #request_http_version ⇒ Object
Constructor Details
#initialize(stream_or_string) ⇒ Parser
Returns a new instance of Parser.
5 6 7 8 9 10 11 |
# File 'lib/minver/parser.rb', line 5 def initialize(stream_or_string) @stream = if stream_or_string.is_a? String StringIO.new(stream_or_string) else stream_or_string end end |
Instance Method Details
#[](key) ⇒ Object
27 28 29 |
# File 'lib/minver/parser.rb', line 27 def [](key) headers[key] end |
#body ⇒ Object
35 36 37 |
# File 'lib/minver/parser.rb', line 35 def body @body ||= @stream.read(headers["Content-Length"].to_i) end |
#data ⇒ Object
31 32 33 |
# File 'lib/minver/parser.rb', line 31 def data @data ||= [*head, body].join end |
#headers ⇒ Object
21 22 23 24 25 |
# File 'lib/minver/parser.rb', line 21 def headers @headers ||= header_lines.inject({}) do |h, line| h.merge(Hash[[line.rstrip.split(': ', 2)]]) end end |
#http_method ⇒ Object
13 14 15 |
# File 'lib/minver/parser.rb', line 13 def http_method @http_method ||= request_match[1] end |
#path ⇒ Object
39 40 41 |
# File 'lib/minver/parser.rb', line 39 def path @path ||= request_uri.first end |
#query_string ⇒ Object
43 44 45 |
# File 'lib/minver/parser.rb', line 43 def query_string @query_string ||= request_uri[1] || '' end |
#request_http_version ⇒ Object
17 18 19 |
# File 'lib/minver/parser.rb', line 17 def request_http_version @request_http_version ||= request_match[3] end |