Class: Rubtella::HTTPData::Parser
- Inherits:
-
Object
- Object
- Rubtella::HTTPData::Parser
- Defined in:
- lib/rubtella/http_data.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http_data ⇒ Object
Returns the value of attribute http_data.
-
#peers ⇒ Object
Returns the value of attribute peers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(http_data) ⇒ Parser
constructor
A new instance of Parser.
- #ok? ⇒ Boolean
- #parse ⇒ Object
Constructor Details
#initialize(http_data) ⇒ Parser
Returns a new instance of Parser.
28 29 30 31 |
# File 'lib/rubtella/http_data.rb', line 28 def initialize http_data @http_data = http_data parse end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
26 27 28 |
# File 'lib/rubtella/http_data.rb', line 26 def data @data end |
#headers ⇒ Object
Returns the value of attribute headers.
26 27 28 |
# File 'lib/rubtella/http_data.rb', line 26 def headers @headers end |
#http_data ⇒ Object
Returns the value of attribute http_data.
26 27 28 |
# File 'lib/rubtella/http_data.rb', line 26 def http_data @http_data end |
#peers ⇒ Object
Returns the value of attribute peers.
26 27 28 |
# File 'lib/rubtella/http_data.rb', line 26 def peers @peers end |
#status ⇒ Object
Returns the value of attribute status.
26 27 28 |
# File 'lib/rubtella/http_data.rb', line 26 def status @status end |
Instance Method Details
#ok? ⇒ Boolean
48 49 50 |
# File 'lib/rubtella/http_data.rb', line 48 def ok? @status =~ /200 OK/ end |
#parse ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubtella/http_data.rb', line 33 def parse @headers = Hash.new @peers = Array.new headers, @data = @http_data.split("\r\n\r\n") headers = headers.split("\r\n") @status = headers.shift headers.each {|h| k,v = h.split(": "); @headers[k] = v} if up = @headers["X-Try-Ultrapeers"] up.split(",").each {|u| ip,port = u.split(":"); @peers << Peer.new(ip,port)} end end |