Class: MooTool::DeviceTree::Node
- Inherits:
-
Object
- Object
- MooTool::DeviceTree::Node
- Extended by:
- T::Sig
- 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mootool/models/device_tree.rb', line 24 def initialize(tree, data) @tree = tree vals = T.must(data.read(8)).unpack(NODE_FORMAT) property_count = T.cast(vals[0], Integer) child_count = T.cast(vals[1], Integer) @properties = T.let({}, T::Hash[String, Property]) @children = T.let([], T::Array[Node]) 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.
21 22 23 |
# File 'lib/mootool/models/device_tree.rb', line 21 def children @children end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
21 22 23 |
# File 'lib/mootool/models/device_tree.rb', line 21 def properties @properties end |
Instance Method Details
#to_h ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/mootool/models/device_tree.rb', line 42 def to_h props = @properties.transform_values(&:value) if @children.any? props.merge({ children: @children.map(&:to_h) }) else props end end |