Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/to_upnp_s.rb,
lib/core_ext/hash_patch.rb

Instance Method Summary collapse

Instance Method Details

#symbolize_keys!Object



2
3
4
# File 'lib/core_ext/hash_patch.rb', line 2

def symbolize_keys!
  self.inject({}) { |result, (k, v)| result[k.to_sym] = v; result }
end

#to_upnp_sString

Converts Hash search targets to SSDP search target String. Conversions are as follows:

uuid: "someUUID"                 # => "uuid:someUUID"
device_type: "someDeviceType:1"    # => "urn:schemas-upnp-org:device:someDeviceType:1"
service_type: "someServiceType:2"  # => "urn:schemas-upnp-org:service:someServiceType:2"

You can use custom UPnP domain names too:

{ device_type: "someDeviceType:3",
domain_name: "mydomain-com" }    # => "urn:my-domain:device:someDeviceType:3"
{ service_type: "someServiceType:4",
domain_name: "mydomain-com" }    # => "urn:my-domain:service:someDeviceType:4"

Returns:

  • (String)

    The converted String, according to the UPnP spec.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/core_ext/to_upnp_s.rb', line 16

def to_upnp_s
  if self.has_key? :uuid
    return "uuid:#{self[:uuid]}"
  elsif self.has_key? :device_type
    if self.has_key? :domain_name
      return "urn:#{self[:domain_name]}:device:#{self[:device_type]}"
    else
      return "urn:schemas-upnp-org:device:#{self[:device_type]}"
    end
  elsif self.has_key? :service_type
    if self.has_key? :domain_name
      return "urn:#{self[:domain_name]}:service:#{self[:service_type]}"
    else
      return "urn:schemas-upnp-org:service:#{self[:service_type]}"
    end
  else
    self.to_s
  end
end