Class: DBus::Node
- Inherits:
-
Hash
- Object
- Hash
- DBus::Node
- Defined in:
- lib/dbus/node_tree.rb
Overview
Object path node class
Class representing a node on an object path.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the node.
-
#object ⇒ DBus::Object, ...
The D-Bus object contained by the node.
Instance Method Summary collapse
-
#descendant_objects ⇒ Array<DBus::Object>
All objects (not paths) under this path (except itself).
-
#initialize(name) ⇒ Node
constructor
Create a new node with a given name.
-
#inspect ⇒ Object
Return inspect information of the node.
-
#sub_inspect ⇒ Object
Return instance inspect information, used by Node#inspect.
-
#to_xml(node_opath) ⇒ Object
Return an XML string representation of the node.
Constructor Details
#initialize(name) ⇒ Node
Create a new node with a given name.
54 55 56 57 58 |
# File 'lib/dbus/node_tree.rb', line 54 def initialize(name) super() @name = name @object = nil end |
Instance Attribute Details
#name ⇒ String (readonly)
The name of the node.
51 52 53 |
# File 'lib/dbus/node_tree.rb', line 51 def name @name end |
#object ⇒ DBus::Object, ...
Returns The D-Bus object contained by the node.
47 48 49 |
# File 'lib/dbus/node_tree.rb', line 47 def object @object end |
Instance Method Details
#descendant_objects ⇒ Array<DBus::Object>
All objects (not paths) under this path (except itself).
98 99 100 101 102 103 |
# File 'lib/dbus/node_tree.rb', line 98 def descendant_objects children_objects = values.map(&:object).compact descendants = values.map(&:descendant_objects) flat_descendants = descendants.reduce([], &:+) children_objects + flat_descendants end |
#inspect ⇒ Object
Return inspect information of the node.
79 80 81 82 |
# File 'lib/dbus/node_tree.rb', line 79 def inspect # Need something here "<DBus::Node #{sub_inspect}>" end |
#sub_inspect ⇒ Object
Return instance inspect information, used by Node#inspect.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dbus/node_tree.rb', line 85 def sub_inspect s = "" if !@object.nil? s += format("%x ", @object.object_id) end contents_sub_inspect = keys .map { |k| "#{k} => #{self[k].sub_inspect}" } .join(",") "#{s}{#{contents_sub_inspect}}" end |
#to_xml(node_opath) ⇒ Object
Return an XML string representation of the node. It is shallow, not recursing into subnodes
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dbus/node_tree.rb', line 63 def to_xml(node_opath) xml = '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> ' xml += "<node name=\"#{node_opath}\">\n" each_key do |k| xml += " <node name=\"#{k}\" />\n" end @object&.intfs&.each_value do |v| xml += v.to_xml end xml += "</node>" xml end |