Class: MooTool::Models::DeviceTree::Node
- Inherits:
-
Object
- Object
- MooTool::Models::DeviceTree::Node
- Defined in:
- lib/mootool/models/device_tree.rb
Overview
Represents a single node in the device tree
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
-
#initialize(tree, data) ⇒ Node
constructor
A new instance of Node.
- #to_h ⇒ Object
Constructor Details
#initialize(tree, data) ⇒ Node
Returns a new instance of Node.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mootool/models/device_tree.rb', line 17 def initialize(tree, data) @tree = tree vals = data.read(8).unpack(NODE_FORMAT) property_count = vals[0] child_count = vals[1] @properties = {} @children = [] property_count.times do prop = Property.new(data) @properties[prop.name] = prop end child_count.times { @children << Node.new(tree, data) } @tree.add_handle(self, T.must(@properties[PHANDLE_PROP]).value) if @properties.key? PHANDLE_PROP end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
15 16 17 |
# File 'lib/mootool/models/device_tree.rb', line 15 def children @children end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
15 16 17 |
# File 'lib/mootool/models/device_tree.rb', line 15 def properties @properties end |
Instance Method Details
#to_h ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/mootool/models/device_tree.rb', line 35 def to_h props = @properties.transform_values(&:value) if @children.any? props.merge({ children: @children.map(&:to_h) }) else props end end |