Class: SimpleUpnp::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_upnp/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Device

Returns a new instance of Device.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_upnp/device.rb', line 8

def initialize(message)
  lines = message.split(/\r?\n/)
  lines.each do |line|
    if line =~ /^ST:/i
      @st = parse_token(line.split(': '))
    elsif line =~ /^SERVER:/i
      @server = parse_token(line.split(': '))
    elsif line =~ /^USN:/i
      @usn = parse_token(line.split(': '))
      # Trim off data after ::
      # For example, we don't want upnp:rootdevice from uuid:7DD8D98F-6577-582D-AF37-38B92EB830A4::upnp:rootdevice
      @usn = @usn.split('::').first
    elsif line =~ /^LOCATION:/i
      @location = parse_token(line.split(': '))
    end
  end
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/simple_upnp/device.rb', line 6

def location
  @location
end

#serverObject (readonly)

Returns the value of attribute server.



6
7
8
# File 'lib/simple_upnp/device.rb', line 6

def server
  @server
end

#stObject (readonly)

Returns the value of attribute st.



6
7
8
# File 'lib/simple_upnp/device.rb', line 6

def st
  @st
end

#usnObject (readonly)

Returns the value of attribute usn.



6
7
8
# File 'lib/simple_upnp/device.rb', line 6

def usn
  @usn
end

Instance Method Details

#to_json(include_location_details = false) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/simple_upnp/device.rb', line 26

def to_json(include_location_details = false)
  h = {
    :st => st,
    :server => server,
    :usn => usn,
    :location => location
  }
  h.merge!(retrieve_location_details) if include_location_details and location
  h
end