Class: Rubtella::HTTPData::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rubtella/http_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



26
27
28
# File 'lib/rubtella/http_data.rb', line 26

def data
  @data
end

#headersObject

Returns the value of attribute headers.



26
27
28
# File 'lib/rubtella/http_data.rb', line 26

def headers
  @headers
end

#http_dataObject

Returns the value of attribute http_data.



26
27
28
# File 'lib/rubtella/http_data.rb', line 26

def http_data
  @http_data
end

#peersObject

Returns the value of attribute peers.



26
27
28
# File 'lib/rubtella/http_data.rb', line 26

def peers
  @peers
end

#statusObject

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/rubtella/http_data.rb', line 48

def ok?
  @status =~ /200 OK/
end

#parseObject



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