Class: NLHue::SSDP::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/nlhue/ssdp.rb

Overview

The HTTP response representing a service discovered by SSDP.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip, response) ⇒ Response

Returns a new instance of Response.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nlhue/ssdp.rb', line 39

def initialize ip, response
	@ip = ip
	@response = response
	@headers = {}

	response.split(/\r?\n\r?\n/, 2)[0].lines.each do |line|
		if line.include? ':'
			key, value = line.split(/: ?/, 2)
			@headers[key.downcase] = value.strip
		end
	end
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



37
38
39
# File 'lib/nlhue/ssdp.rb', line 37

def headers
  @headers
end

#ipObject (readonly)

Returns the value of attribute ip.



37
38
39
# File 'lib/nlhue/ssdp.rb', line 37

def ip
  @ip
end

#responseObject (readonly)

Returns the value of attribute response.



37
38
39
# File 'lib/nlhue/ssdp.rb', line 37

def response
  @response
end

Instance Method Details

#[](header) ⇒ Object

Retrieves the value of a header, with case insensitive matching.



58
59
60
# File 'lib/nlhue/ssdp.rb', line 58

def [] header
	@headers[header.downcase]
end

#to_sObject



52
53
54
# File 'lib/nlhue/ssdp.rb', line 52

def to_s
	"#{@ip}:\n\t#{@response.lines.to_a.join("\t")}"
end