Class: NLHue::SSDP::Response
- Inherits:
-
Object
- Object
- NLHue::SSDP::Response
- Defined in:
- lib/nlhue/ssdp.rb
Overview
The HTTP response representing a service discovered by SSDP.
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#[](header) ⇒ Object
Retrieves the value of a header, with case insensitive matching.
-
#initialize(ip, response) ⇒ Response
constructor
A new instance of Response.
- #to_s ⇒ Object
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
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
37 38 39 |
# File 'lib/nlhue/ssdp.rb', line 37 def headers @headers end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
37 38 39 |
# File 'lib/nlhue/ssdp.rb', line 37 def ip @ip end |
#response ⇒ Object (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_s ⇒ Object
52 53 54 |
# File 'lib/nlhue/ssdp.rb', line 52 def to_s "#{@ip}:\n\t#{@response.lines.to_a.join("\t")}" end |