Class: MooTool::DeviceTree

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mootool/models/device_tree.rb

Overview

DeviceTree is a Apple Device Tree node that has been parsed

Defined Under Namespace

Classes: Node, Property

Constant Summary collapse

NODE_FORMAT =
'VV'
PROP_FORMAT =
'A32V'
PHANDLE_PROP =
'AAPL,phandle'
COMPATIBLE_PROP =
'compatible'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ DeviceTree

Returns a new instance of DeviceTree.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/mootool/models/device_tree.rb', line 91

def initialize(data)
  @handles = {}
  case data
  when Pathname
    data = T.assert_type!(data, Pathname)
    @data = File.open(data.realpath, 'rb')
  when String
    data = T.assert_type!(data, String)
    @data = StringIO.new(data)
  when IO
    @data = T.let(data, T.any(IO, StringIO))
  end
  @root = Node.new(self, @data)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



87
88
89
# File 'lib/mootool/models/device_tree.rb', line 87

def root
  @root
end

Class Method Details

.open(path) ⇒ Object



111
112
113
# File 'lib/mootool/models/device_tree.rb', line 111

def self.open(path)
  MooTool::DeviceTree.new(Pathname.new(path))
end

Instance Method Details

#add_handle(node, handle) ⇒ Object



106
107
108
# File 'lib/mootool/models/device_tree.rb', line 106

def add_handle(node, handle)
  @handles[handle] = node
end

#to_hObject



115
116
117
# File 'lib/mootool/models/device_tree.rb', line 115

def to_h
  @root.to_h
end