Class: MooTool::Models::IOReg::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/mootool/models/io_reg.rb

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Node

Returns a new instance of Node.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mootool/models/io_reg.rb', line 9

def initialize(node)
  @children = node[:IORegistryEntryChildren] || []
  @name = node[:IORegistryEntryName].to_sym

  node.delete :IORegistryEntryChildren
  node.delete :IORegistryEntryName

  children_nodes = @children.to_h { |child| [child[:IORegistryEntryName].to_sym, Node.new(child)] }
  @properties = node

  @properties.transform_values! do |value|
    case value
    when nil
      nil
    when /([^\0]+)\x00/
      value.strip("\0")
    when CFPropertyList::Blob, String
      value.to_s
    else
      value
    end
  end

  @data = @properties.merge(children_nodes)
end

Instance Method Details

#[](key) ⇒ Object



35
36
37
# File 'lib/mootool/models/io_reg.rb', line 35

def [](key)
  @data[key]
end

#delete(key) ⇒ Object



39
40
41
# File 'lib/mootool/models/io_reg.rb', line 39

def delete(key)
  @data.delete(key)
end

#inspectObject



51
52
53
# File 'lib/mootool/models/io_reg.rb', line 51

def inspect
  to_h.ai
end

#selectObject



43
44
45
# File 'lib/mootool/models/io_reg.rb', line 43

def select(&)
  @data.select(&)
end

#to_hObject



47
48
49
# File 'lib/mootool/models/io_reg.rb', line 47

def to_h
  @data
end