Class: NicInfo::DataTree

Inherits:
Object
  • Object
show all
Defined in:
lib/nicinfo/data_tree.rb

Instance Method Summary collapse

Constructor Details

#initializeDataTree

Returns a new instance of DataTree.



61
62
63
# File 'lib/nicinfo/data_tree.rb', line 61

def initialize
  @roots = []
end

Instance Method Details

#add_child(node) ⇒ Object



69
70
71
# File 'lib/nicinfo/data_tree.rb', line 69

def add_child node
  add_root( node )
end

#add_children_as_root(node) ⇒ Object



73
74
75
76
77
# File 'lib/nicinfo/data_tree.rb', line 73

def add_children_as_root node
  node.children.each do |child|
    add_root( child )
  end if node
end

#add_root(node) ⇒ Object



65
66
67
# File 'lib/nicinfo/data_tree.rb', line 65

def add_root node
  @roots << node if node
end

#empty?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/nicinfo/data_tree.rb', line 83

def empty?
  @roots.empty?
end

#find_data(data_address) ⇒ Object



87
88
89
90
91
# File 'lib/nicinfo/data_tree.rb', line 87

def find_data data_address
  node = find_node data_address
  return node.data if node
  return nil
end

#find_handle(data_address) ⇒ Object



93
94
95
96
97
# File 'lib/nicinfo/data_tree.rb', line 93

def find_handle data_address
  node = find_node data_address
  return node.handle if node
  return nil
end

#find_node(data_address) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/nicinfo/data_tree.rb', line 105

def find_node data_address
  node = NicInfo::DataNode.new( "fakeroot" )
  node.children=roots
  data_address.split( /\D/ ).each do |index_str|
    index = index_str.to_i - 1
    node = node.children[ index ] if node
  end
  if node != nil
    return node
  end
  #else
  return nil
end

#find_rest_ref(data_address) ⇒ Object



99
100
101
102
103
# File 'lib/nicinfo/data_tree.rb', line 99

def find_rest_ref data_address
  node = find_node data_address
  return node.rest_ref if node
  return nil
end

#rootsObject



79
80
81
# File 'lib/nicinfo/data_tree.rb', line 79

def roots
  @roots
end

#to_extra_log(logger, annotate = false) ⇒ Object



131
132
133
134
135
# File 'lib/nicinfo/data_tree.rb', line 131

def to_extra_log logger, annotate = false
  @logger = logger
  @data_amount = DataAmount::EXTRA_DATA
  to_log( annotate )
end

#to_normal_log(logger, annotate = false) ⇒ Object



125
126
127
128
129
# File 'lib/nicinfo/data_tree.rb', line 125

def to_normal_log logger, annotate = false
  @logger = logger
  @data_amount = DataAmount::NORMAL_DATA
  to_log( annotate )
end

#to_terse_log(logger, annotate = false) ⇒ Object



119
120
121
122
123
# File 'lib/nicinfo/data_tree.rb', line 119

def to_terse_log logger, annotate = false
  @logger = logger
  @data_amount = DataAmount::TERSE_DATA
  to_log( annotate )
end